@@ -120,6 +120,11 @@ func runSteps(ctx context.Context, wc *WorkspaceCreator, repo *graphql.Repositor
120120 filesToMount [name ] = fp .Name ()
121121 }
122122
123+ env , err := parseStepEnv (step .Env , & stepContext )
124+ if err != nil {
125+ return nil , errors .Wrap (err , "parsing step files" )
126+ }
127+
123128 tmpl , err := parseStepRun (step .Run , & stepContext )
124129 if err != nil {
125130 return nil , errors .Wrap (err , "parsing step run" )
@@ -145,12 +150,14 @@ func runSteps(ctx context.Context, wc *WorkspaceCreator, repo *graphql.Repositor
145150 for target , source := range filesToMount {
146151 args = append (args , "--mount" , fmt .Sprintf ("type=bind,source=%s,target=%s,ro" , source , target ))
147152 }
153+
154+ for k , v := range env {
155+ args = append (args , "-e" , k + "=" + v )
156+ }
157+
148158 args = append (args , "--entrypoint" , shell )
149159
150160 cmd := exec .CommandContext (ctx , "docker" , args ... )
151- for k , v := range step .Env {
152- cmd .Args = append (cmd .Args , "-e" , k + "=" + v )
153- }
154161 cmd .Args = append (cmd .Args , "--" , step .image , containerTemp )
155162 cmd .Dir = volumeDir
156163
@@ -354,6 +361,31 @@ func parseStepFiles(files map[string]interface{}, stepCtx *StepContext) (map[str
354361 return containerFiles , nil
355362}
356363
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+
357389// StepContext represents the contextual information available when executing a
358390// step that's defined in a campaign spec.
359391type StepContext struct {
0 commit comments