Skip to content

Commit

Permalink
feat(pipeline_template): Jinja rendering in partials (#1637)
Browse files Browse the repository at this point in the history
Renders the partials' stage config before rendering partials, to allow
for more advanced jinja expressions in the partials.
  • Loading branch information
jervi authored and robzienert committed Sep 21, 2017
1 parent ae66a6b commit 5d66215
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ private void renderPartials(List<PartialDefinition> partials, List<StageDefiniti
);

RenderContext partialContext = context.copy();
partialContext.setLocation(String.format("template:stages.%s", stage.getId()));
renderStage(stage, partialContext, "template");
partialContext.getVariables().putAll(stage.getConfig());
partialContext.setLocation(String.format("partial:%s.%s", stage.getId(), partial.getId()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,15 @@ class PipelineTemplatePipelinePreprocessorSpec extends Specification {
result.stages*.group == ['my group of stages: wowow waiting', 'my group of stages: wowow waiting']
}

def 'should render stage config variables used in partials'() {
when:
def template = createTemplateRequest('conditional-partials.yml', [includeWait: false])
def result = subject.process(template)

then:
result.stages*.shouldBeSet == ["isSet"]
}

@Unroll
def 'should not render falsy conditional stages inside partials'() {
when:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@ id: simpleTemplate
variables:
- name: includeWait
type: boolean
- name: someVariable
defaultValue: someValue
stages:
- id: stageWithPartialsAndConditional
type: partial.partialWithConditional
dependsOn: []
config: {}
config:
anotherVariable: "{{ someVariable }}"

partials:
- id: partialWithConditional
usage: Partial that conditionally adds a step
variables: []
variables:
- name: anotherVariable
stages:
- id: conditionalWaitOnPartial
type: wait
Expand All @@ -24,3 +28,4 @@ partials:
type: wait
config:
waitTime: 5
shouldBeSet: "{{ 'isSet' if anotherVariable == someVariable else 'notSet' }}"

0 comments on commit 5d66215

Please sign in to comment.