@@ -34,15 +34,15 @@ 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
- preCreatedWorkingDir string
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
+ preCreatedCloneDir string
46
46
}
47
47
48
48
var (
@@ -63,14 +63,14 @@ func NewExecutor(
63
63
Secret : clientToken ,
64
64
}
65
65
return & Executor {
66
- taskIdentification : taskIdentification ,
67
- serverToken : serverToken ,
68
- backgroundCommands : make ([]CommandAndLogs , 0 ),
69
- httpCacheHost : "" ,
70
- sensitiveValues : make ([]string , 0 ),
71
- commandFrom : commandFrom ,
72
- commandTo : commandTo ,
73
- preCreatedWorkingDir : preCreatedWorkingDir ,
66
+ taskIdentification : taskIdentification ,
67
+ serverToken : serverToken ,
68
+ backgroundCommands : make ([]CommandAndLogs , 0 ),
69
+ httpCacheHost : "" ,
70
+ sensitiveValues : make ([]string , 0 ),
71
+ commandFrom : commandFrom ,
72
+ commandTo : commandTo ,
73
+ preCreatedCloneDir : preCreatedWorkingDir ,
74
74
}
75
75
}
76
76
@@ -190,26 +190,32 @@ func getExpandedScriptEnvironment(executor *Executor, responseEnvironment map[st
190
190
}
191
191
responseEnvironment ["CIRRUS_OS" ] = runtime .GOOS
192
192
193
- // Use directory created by the persistent worker if CIRRUS_WORKING_DIR
193
+ // Use directory created by the persistent worker if CIRRUS_CLONE_DIR
194
194
// was not overridden in the task specification by the user
195
- _ , hasWorkingDir := responseEnvironment ["CIRRUS_WORKING_DIR " ]
196
- if ! hasWorkingDir && executor .preCreatedWorkingDir != "" {
197
- responseEnvironment ["CIRRUS_WORKING_DIR " ] = executor .preCreatedWorkingDir
195
+ _ , hasWorkingDir := responseEnvironment ["CIRRUS_CLONE_DIR " ]
196
+ if ! hasWorkingDir && executor .preCreatedCloneDir != "" {
197
+ responseEnvironment ["CIRRUS_CLONE_DIR " ] = executor .preCreatedCloneDir
198
198
}
199
199
200
- if _ , ok := responseEnvironment ["CIRRUS_WORKING_DIR" ]; ! ok {
200
+ // Set CIRRUS_CLONE_DIR if not already set by the user (1) or by us above (2)
201
+ if _ , ok := responseEnvironment ["CIRRUS_CLONE_DIR" ]; ! ok {
201
202
defaultTempDirPath := filepath .Join (os .TempDir (), "cirrus-ci-build" )
202
203
if _ , err := os .Stat (defaultTempDirPath ); os .IsNotExist (err ) {
203
- responseEnvironment ["CIRRUS_WORKING_DIR " ] = filepath .ToSlash (defaultTempDirPath )
204
+ responseEnvironment ["CIRRUS_CLONE_DIR " ] = filepath .ToSlash (defaultTempDirPath )
204
205
} else if executor .commandFrom != "" {
205
206
// Default folder exists and we continue execution. Therefore we need to use it.
206
- responseEnvironment ["CIRRUS_WORKING_DIR " ] = filepath .ToSlash (defaultTempDirPath )
207
+ responseEnvironment ["CIRRUS_CLONE_DIR " ] = filepath .ToSlash (defaultTempDirPath )
207
208
} else {
208
209
uniqueTempDirPath , _ := ioutil .TempDir (os .TempDir (), fmt .Sprintf ("cirrus-task-%d" , executor .taskIdentification .TaskId ))
209
- responseEnvironment ["CIRRUS_WORKING_DIR " ] = filepath .ToSlash (uniqueTempDirPath )
210
+ responseEnvironment ["CIRRUS_CLONE_DIR " ] = filepath .ToSlash (uniqueTempDirPath )
210
211
}
211
212
}
212
213
214
+ // Set CIRRUS_WORKING_DIR if not already set by the user (1) or by us above (2)
215
+ if _ , ok := responseEnvironment ["CIRRUS_WORKING_DIR" ]; ! ok {
216
+ responseEnvironment ["CIRRUS_WORKING_DIR" ] = "${CIRRUS_CLONE_DIR}"
217
+ }
218
+
213
219
result := expandEnvironmentRecursively (responseEnvironment )
214
220
215
221
return result
@@ -386,7 +392,7 @@ func (executor *Executor) CloneRepository(env map[string]string) bool {
386
392
387
393
logUploader .Write ([]byte ("Using built-in Git...\n " ))
388
394
389
- working_dir := env ["CIRRUS_WORKING_DIR " ]
395
+ cloneDir := env ["CIRRUS_CLONE_DIR " ]
390
396
change := env ["CIRRUS_CHANGE_IN_REPO" ]
391
397
branch := env ["CIRRUS_BRANCH" ]
392
398
pr_number , is_pr := env ["CIRRUS_PR" ]
@@ -426,7 +432,7 @@ func (executor *Executor) CloneRepository(env map[string]string) bool {
426
432
var repo * git.Repository
427
433
428
434
if is_pr {
429
- repo , err = git .PlainInit (working_dir , false )
435
+ repo , err = git .PlainInit (cloneDir , false )
430
436
if err != nil {
431
437
logUploader .Write ([]byte (fmt .Sprintf ("\n Failed to init repository: %s!" , err )))
432
438
return false
@@ -498,13 +504,13 @@ func (executor *Executor) CloneRepository(env map[string]string) bool {
498
504
}
499
505
logUploader .Write ([]byte (fmt .Sprintf ("\n Cloning %s...\n " , cloneOptions .ReferenceName )))
500
506
501
- repo , err = git .PlainClone (working_dir , false , & cloneOptions )
507
+ repo , err = git .PlainClone (cloneDir , false , & cloneOptions )
502
508
503
509
if err != nil && retryableCloneError (err ) {
504
510
logUploader .Write ([]byte (fmt .Sprintf ("\n Retryable error '%s' while cloning! Trying again..." , err )))
505
- os .RemoveAll (working_dir )
506
- EnsureFolderExists (working_dir )
507
- repo , err = git .PlainClone (working_dir , false , & cloneOptions )
511
+ os .RemoveAll (cloneDir )
512
+ EnsureFolderExists (cloneDir )
513
+ repo , err = git .PlainClone (cloneDir , false , & cloneOptions )
508
514
}
509
515
510
516
if err != nil {
0 commit comments