Skip to content

Commit

Permalink
feat(mptv1): Support templated stage IDs in looped stages (#2977)
Browse files Browse the repository at this point in the history
  • Loading branch information
robzienert committed Jun 17, 2019
1 parent fe0e621 commit 1aaa72c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,19 @@ private void expandLoops(List<StageDefinition> stages, RenderContext context) {
int index = 0;
for (Object value : (Collection) loopValue) {
StageDefinition expandedStage = wrapClone(stage);
expandedStage.setId(stage.getId() + index);

expandedStage.getLoopContext().put("value", value);
expandedStage.setLoopWith(null);

// If the stage ID is templated, allow access to the templateLoop context for rendering.
if (stage.getId().contains("{{") && stage.getId().contains("}}")) {
RenderContext loopedContext = context.copy();
loopedContext.getVariables().put("templateLoop", expandedStage.getLoopContext());
expandedStage.setId(renderer.render(stage.getId(), loopedContext));
} else {
expandedStage.setId(stage.getId() + index);
}

stage.getLoopedStages().add(expandedStage);

index++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@
"requisiteStageRefIds": ["joinWait"],
"name": "Wait 5 seconds",
"id": null,
"refId": "stageLoop0",
"refId": "stageLoop-5",
"type": "wait",
"waitTime": 5
},
{
"requisiteStageRefIds": ["joinWait"],
"name": "Wait 10 seconds",
"id": null,
"refId": "stageLoop1",
"refId": "stageLoop-10",
"type": "wait",
"waitTime": 10
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ stages:
waitTime: 3
dependsOn:
- loopedPartial
- id: stageLoop
- id: "stageLoop-{{ templateLoop.value }}"
type: wait
name: "Wait {{ templateLoop.value }} seconds"
config:
Expand Down

0 comments on commit 1aaa72c

Please sign in to comment.