@@ -34,31 +34,38 @@ type CommandAndLogs struct {
34
34
}
35
35
36
36
type Executor struct {
37
- taskIdentification * api.TaskIdentification
38
- serverToken string
39
- backgroundCommands []CommandAndLogs
40
- httpCacheHost string
41
- timeout <- chan time.Time
42
- sensitiveValues []string
43
- commandFrom string
44
- commandTo string
45
- cleanWorkingDir bool
37
+ taskIdentification * api.TaskIdentification
38
+ serverToken string
39
+ backgroundCommands []CommandAndLogs
40
+ httpCacheHost string
41
+ timeout <- chan time.Time
42
+ sensitiveValues []string
43
+ commandFrom string
44
+ commandTo string
45
+ preCreatedWorkingDir string
46
46
}
47
47
48
- func NewExecutor (taskId int64 , clientToken , serverToken string , commandFrom string , commandTo string , cleanWorkingDir bool ) * Executor {
48
+ func NewExecutor (
49
+ taskId int64 ,
50
+ clientToken ,
51
+ serverToken string ,
52
+ commandFrom string ,
53
+ commandTo string ,
54
+ preCreatedWorkingDir string ,
55
+ ) * Executor {
49
56
taskIdentification := & api.TaskIdentification {
50
57
TaskId : taskId ,
51
58
Secret : clientToken ,
52
59
}
53
60
return & Executor {
54
- taskIdentification : taskIdentification ,
55
- serverToken : serverToken ,
56
- backgroundCommands : make ([]CommandAndLogs , 0 ),
57
- httpCacheHost : "" ,
58
- sensitiveValues : make ([]string , 0 ),
59
- commandFrom : commandFrom ,
60
- commandTo : commandTo ,
61
- cleanWorkingDir : cleanWorkingDir ,
61
+ taskIdentification : taskIdentification ,
62
+ serverToken : serverToken ,
63
+ backgroundCommands : make ([]CommandAndLogs , 0 ),
64
+ httpCacheHost : "" ,
65
+ sensitiveValues : make ([]string , 0 ),
66
+ commandFrom : commandFrom ,
67
+ commandTo : commandTo ,
68
+ preCreatedWorkingDir : preCreatedWorkingDir ,
62
69
}
63
70
}
64
71
@@ -141,12 +148,6 @@ func (executor *Executor) RunBuild() {
141
148
}
142
149
backgroundCommand .Logs .Finalize ()
143
150
}
144
- if executor .cleanWorkingDir {
145
- err = os .RemoveAll (workingDir )
146
- if err != nil {
147
- log .Printf ("Failed to clean working directory: %v" , err )
148
- }
149
- }
150
151
}
151
152
152
153
// BoundedCommands bounds a slice of commands with unique names to a half-open range [fromName, toName).
@@ -178,6 +179,13 @@ func getExpandedScriptEnvironment(executor *Executor, responseEnvironment map[st
178
179
}
179
180
responseEnvironment ["CIRRUS_OS" ] = runtime .GOOS
180
181
182
+ // Use directory created by the persistent worker if CIRRUS_WORKING_DIR
183
+ // was not overridden in the task specification by the user
184
+ _ , needsWorkingDir := responseEnvironment ["CIRRUS_WORKING_DIR" ]
185
+ if needsWorkingDir && executor .preCreatedWorkingDir != "" {
186
+ responseEnvironment ["CIRRUS_WORKING_DIR" ] = executor .preCreatedWorkingDir
187
+ }
188
+
181
189
if _ , ok := responseEnvironment ["CIRRUS_WORKING_DIR" ]; ! ok {
182
190
defaultTempDirPath := filepath .Join (os .TempDir (), "cirrus-ci-build" )
183
191
if _ , err := os .Stat (defaultTempDirPath ); os .IsNotExist (err ) {
0 commit comments