@@ -120,6 +120,11 @@ func runSteps(ctx context.Context, wc *WorkspaceCreator, repo *graphql.Repositor
120
120
filesToMount [name ] = fp .Name ()
121
121
}
122
122
123
+ env , err := parseStepEnv (step .Env , & stepContext )
124
+ if err != nil {
125
+ return nil , errors .Wrap (err , "parsing step files" )
126
+ }
127
+
123
128
tmpl , err := parseStepRun (step .Run , & stepContext )
124
129
if err != nil {
125
130
return nil , errors .Wrap (err , "parsing step run" )
@@ -145,12 +150,14 @@ func runSteps(ctx context.Context, wc *WorkspaceCreator, repo *graphql.Repositor
145
150
for target , source := range filesToMount {
146
151
args = append (args , "--mount" , fmt .Sprintf ("type=bind,source=%s,target=%s,ro" , source , target ))
147
152
}
153
+
154
+ for k , v := range env {
155
+ args = append (args , "-e" , k + "=" + v )
156
+ }
157
+
148
158
args = append (args , "--entrypoint" , shell )
149
159
150
160
cmd := exec .CommandContext (ctx , "docker" , args ... )
151
- for k , v := range step .Env {
152
- cmd .Args = append (cmd .Args , "-e" , k + "=" + v )
153
- }
154
161
cmd .Args = append (cmd .Args , "--" , step .image , containerTemp )
155
162
cmd .Dir = volumeDir
156
163
@@ -354,6 +361,31 @@ func parseStepFiles(files map[string]interface{}, stepCtx *StepContext) (map[str
354
361
return containerFiles , nil
355
362
}
356
363
364
+ func parseStepEnv (env map [string ]string , stepCtx * StepContext ) (map [string ]string , error ) {
365
+ parsedEnv := make (map [string ]string , len (env ))
366
+
367
+ fnMap := stepCtx .ToFuncMap ()
368
+
369
+ for k , v := range env {
370
+ // We treat the file contents as a template and render it
371
+ // into a buffer that we then mount into the code host.
372
+ var out bytes.Buffer
373
+
374
+ tmpl , err := template .New (k ).Delims ("${{" , "}}" ).Funcs (fnMap ).Parse (v )
375
+ if err != nil {
376
+ return parsedEnv , err
377
+ }
378
+
379
+ if err := tmpl .Execute (& out , stepCtx ); err != nil {
380
+ return parsedEnv , err
381
+ }
382
+
383
+ parsedEnv [k ] = out .String ()
384
+ }
385
+
386
+ return parsedEnv , nil
387
+ }
388
+
357
389
// StepContext represents the contextual information available when executing a
358
390
// step that's defined in a campaign spec.
359
391
type StepContext struct {
0 commit comments