Skip to content

Commit

Permalink
fix(worker): worker export variable were not accessible from next step
Browse files Browse the repository at this point in the history
  • Loading branch information
sguiheux authored and richardlt committed Jan 17, 2020
1 parent 7ec11da commit fdcf011
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
16 changes: 16 additions & 0 deletions engine/worker/internal/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ func (w *CurrentWorker) runJob(ctx context.Context, a *sdk.Action, jobID int64,
if nCriticalFailed == 0 || step.AlwaysExecuted {
stepResult = w.runAction(ctx, step, jobID, secrets, step.Name)

// Check if all newVariables are in currentJob.params
// variable can be add in w.currentJob.newVariables by worker command export
for _, newVariableFromHandler := range w.currentJob.newVariables {
if sdk.ParameterFind(w.currentJob.params, newVariableFromHandler.Name) == nil {
w.currentJob.params = append(w.currentJob.params, newVariableFromHandler.ToParameter(""))
}
}

for _, newVariable := range stepResult.NewVariables {
// append the new variable from a step to the following steps
w.currentJob.params = append(w.currentJob.params, newVariable.ToParameter("cds.build"))
Expand Down Expand Up @@ -259,6 +267,14 @@ func (w *CurrentWorker) runSteps(ctx context.Context, steps []sdk.Action, a sdk.
r.Status = sdk.StatusNeverBuilt
}

// Check if all newVariables are in currentJob.params
// variable can be add in w.currentJob.newVariables by worker command export
for _, newVariableFromHandler := range w.currentJob.newVariables {
if sdk.ParameterFind(w.currentJob.params, newVariableFromHandler.Name) == nil {
w.currentJob.params = append(w.currentJob.params, newVariableFromHandler.ToParameter(""))
}
}

for _, newVariable := range r.NewVariables {
// append the new variable from a chile to the following children
w.currentJob.params = append(w.currentJob.params, newVariable.ToParameter("cds.build"))
Expand Down
6 changes: 5 additions & 1 deletion sdk/variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ type Variable struct {
}

func (v Variable) ToParameter(prefix string) Parameter {
name := v.Name
if prefix != "" {
name = fmt.Sprintf("%s.%s", prefix, v.Name)
}
return Parameter{
Name: "." + prefix + "." + v.Name,
Name: name,
Value: v.Value,
Type: v.Type,
}
Expand Down

0 comments on commit fdcf011

Please sign in to comment.