Skip to content

Commit

Permalink
fix(stageExecution): In evaluable variable stage restart scenario var…
Browse files Browse the repository at this point in the history
…iables are not cleaned properly (#16) (backport #4307) (#4327)

Co-authored-by: Oscar Michel Herrera <oscarmichelh@gmail.com>
  • Loading branch information
mergify[bot] and OscarMichelH committed Nov 8, 2022
1 parent 3ac8a17 commit 5dc3920
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
Expand Up @@ -49,6 +49,22 @@ public void taskGraph(@Nonnull StageExecution stage, @Nonnull TaskNode.Builder b
builder.withTask("evaluateVariables", EvaluateVariablesTask.class);
}

@Override
public void prepareStageForRestart(@Nonnull StageExecution stage) {
stage.getOutputs().clear();
EvaluateVariablesStageContext context = stage.mapTo(EvaluateVariablesStageContext.class);

List<Variable> variables =
Optional.ofNullable(context.getVariables()).orElse(Collections.emptyList());
for (Variable var : variables) {
if (var.sourceExpression instanceof String) {
var.value = var.sourceExpression.toString().replace("{", "${");
var.sourceExpression = null;
}
}
stage.getContext().put("variables", variables);
}

@Override
public boolean processExpressions(
@Nonnull StageExecution stage,
Expand Down
Expand Up @@ -81,4 +81,29 @@ class EvaluateVariablesStageSpec extends Specification {
shouldContinue == false
stage.context.notifications[0].address == "someone@somewhere.com"
}

void "Should correctly clean variables in restart scenario"() {
setup:
def summary = new ExpressionEvaluationSummary()

def stage = stage {
refId = "1"
type = "evaluateVariables"
context["variables"] = [
["key": "status", "value": "expressionToEvaluate"],
]
}

when:
evaluateVariablesStage.processExpressions(stage, contextParameterProcessor, summary)
evaluateVariablesStage.prepareStageForRestart(stage)
def variables = stage.mapTo(EvaluateVariablesStage.EvaluateVariablesStageContext.class).getVariables()
def variablesCleaned = false
variables.each {
variablesCleaned = it.sourceExpression == null
}

then:
variablesCleaned == true
}
}

0 comments on commit 5dc3920

Please sign in to comment.