diff --git a/orca-pipelinetemplate/src/main/java/com/netflix/spinnaker/orca/pipelinetemplate/v1schema/V1SchemaExecutionGenerator.java b/orca-pipelinetemplate/src/main/java/com/netflix/spinnaker/orca/pipelinetemplate/v1schema/V1SchemaExecutionGenerator.java index 47f0155ce7..37750b9424 100644 --- a/orca-pipelinetemplate/src/main/java/com/netflix/spinnaker/orca/pipelinetemplate/v1schema/V1SchemaExecutionGenerator.java +++ b/orca-pipelinetemplate/src/main/java/com/netflix/spinnaker/orca/pipelinetemplate/v1schema/V1SchemaExecutionGenerator.java @@ -51,6 +51,7 @@ public Map generate(PipelineTemplate template, TemplateConfigura } addNotifications(pipeline, template, configuration); + addParameters(pipeline, template, configuration); pipeline.put("stages", template.getStages() .stream() @@ -91,4 +92,21 @@ private void addNotifications(Map pipeline, PipelineTemplate tem ); } } + + private void addParameters(Map pipeline, PipelineTemplate template, TemplateConfiguration configuration) { + if (configuration.getConfiguration().getInherit().contains("parameters")) { + pipeline.put( + "parameterConfig", + TemplateMerge.mergeNamedContent( + template.getConfiguration().getParameters(), + configuration.getConfiguration().getParameters() + ) + ); + } else { + pipeline.put( + "parameterConfig", + Optional.ofNullable(configuration.getConfiguration().getParameters()).orElse(Collections.emptyList()) + ); + } + } } diff --git a/orca-pipelinetemplate/src/main/java/com/netflix/spinnaker/orca/pipelinetemplate/v1schema/graph/transform/RenderTransform.java b/orca-pipelinetemplate/src/main/java/com/netflix/spinnaker/orca/pipelinetemplate/v1schema/graph/transform/RenderTransform.java index 99b0eb5205..6bc1391343 100644 --- a/orca-pipelinetemplate/src/main/java/com/netflix/spinnaker/orca/pipelinetemplate/v1schema/graph/transform/RenderTransform.java +++ b/orca-pipelinetemplate/src/main/java/com/netflix/spinnaker/orca/pipelinetemplate/v1schema/graph/transform/RenderTransform.java @@ -20,6 +20,7 @@ import com.netflix.spinnaker.orca.pipelinetemplate.exceptions.IllegalTemplateConfigurationException; import com.netflix.spinnaker.orca.pipelinetemplate.exceptions.TemplateRenderException; import com.netflix.spinnaker.orca.pipelinetemplate.v1schema.PipelineTemplateVisitor; +import com.netflix.spinnaker.orca.pipelinetemplate.v1schema.model.NamedHashMap; import com.netflix.spinnaker.orca.pipelinetemplate.v1schema.model.PartialDefinition; import com.netflix.spinnaker.orca.pipelinetemplate.v1schema.model.PipelineTemplate; import com.netflix.spinnaker.orca.pipelinetemplate.v1schema.model.StageDefinition; @@ -74,6 +75,15 @@ private void render(PipelineTemplate template) { // We don't care about configuration partials, they were already merged into the template at this point renderPartials(template.getPartials(), filterStages(template.getStages(), true), context); + + renderConfigurations(template.getConfiguration().getParameters(), context, "template:configuration.parameters"); + renderConfigurations(templateConfiguration.getConfiguration().getParameters(), context, "configuration:configuration.parameters"); + + renderConfigurations(template.getConfiguration().getTriggers(), context, "template:configuration.triggers"); + renderConfigurations(templateConfiguration.getConfiguration().getTriggers(), context, "configuration:configuration.triggers"); + + renderConfigurations(template.getConfiguration().getNotifications(), context, "template:configuration.notifications"); + renderConfigurations(templateConfiguration.getConfiguration().getNotifications(), context, "configuration:configuration.notifications"); } private void renderStages(List stages, RenderContext context, String locationNamespace) { @@ -196,4 +206,25 @@ private void renderPartials(List partials, List configurations, RenderContext context, String location) { + if (configurations == null) { + return; + } + + for (Map config : configurations) { + for (Map.Entry pair : config.entrySet()) { + try { + pair.setValue(RenderUtil.deepRender(renderer, pair.getValue(), context)); + } catch (TemplateRenderException e) { + throw TemplateRenderException.fromError( + new Error() + .withMessage("Failed rendering configuration property") + .withLocation(location), + e + ); + } + } + } + } } diff --git a/orca-pipelinetemplate/src/test/groovy/com/netflix/spinnaker/orca/pipelinetemplate/PipelineTemplatePipelinePreprocessorSpec.groovy b/orca-pipelinetemplate/src/test/groovy/com/netflix/spinnaker/orca/pipelinetemplate/PipelineTemplatePipelinePreprocessorSpec.groovy index 0e787453f6..1686f6ff29 100644 --- a/orca-pipelinetemplate/src/test/groovy/com/netflix/spinnaker/orca/pipelinetemplate/PipelineTemplatePipelinePreprocessorSpec.groovy +++ b/orca-pipelinetemplate/src/test/groovy/com/netflix/spinnaker/orca/pipelinetemplate/PipelineTemplatePipelinePreprocessorSpec.groovy @@ -152,7 +152,8 @@ class PipelineTemplatePipelinePreprocessorSpec extends Specification { requisiteStageRefIds: ['tagImage'], waitTime: 5 ] - ] + ], + parameterConfig: [] ] assertReflectionEquals(expected, result, ReflectionComparatorMode.IGNORE_DEFAULTS) } diff --git a/orca-pipelinetemplate/src/test/resources/integration/v1schema/conditionalStage-expected.json b/orca-pipelinetemplate/src/test/resources/integration/v1schema/conditionalStage-expected.json index 2785b08553..c87852b78c 100644 --- a/orca-pipelinetemplate/src/test/resources/integration/v1schema/conditionalStage-expected.json +++ b/orca-pipelinetemplate/src/test/resources/integration/v1schema/conditionalStage-expected.json @@ -5,5 +5,6 @@ "application": "orca", "name": "Unnamed Execution", "stages": [], - "notifications": [] + "notifications": [], + "parameterConfig": [] } diff --git a/orca-pipelinetemplate/src/test/resources/integration/v1schema/inheritance-expected.json b/orca-pipelinetemplate/src/test/resources/integration/v1schema/inheritance-expected.json index 333195cb1f..528c521220 100644 --- a/orca-pipelinetemplate/src/test/resources/integration/v1schema/inheritance-expected.json +++ b/orca-pipelinetemplate/src/test/resources/integration/v1schema/inheritance-expected.json @@ -30,5 +30,6 @@ } ], "id": "unknown", - "notifications": [] + "notifications": [], + "parameterConfig": [] } diff --git a/orca-pipelinetemplate/src/test/resources/integration/v1schema/modules-expected.json b/orca-pipelinetemplate/src/test/resources/integration/v1schema/modules-expected.json index f8c41a323d..5ad1ed2be0 100644 --- a/orca-pipelinetemplate/src/test/resources/integration/v1schema/modules-expected.json +++ b/orca-pipelinetemplate/src/test/resources/integration/v1schema/modules-expected.json @@ -35,5 +35,6 @@ ] } ], - "notifications": [] + "notifications": [], + "parameterConfig": [] } diff --git a/orca-pipelinetemplate/src/test/resources/integration/v1schema/partials-expected.json b/orca-pipelinetemplate/src/test/resources/integration/v1schema/partials-expected.json index d3d984f304..23a2ab5fd6 100644 --- a/orca-pipelinetemplate/src/test/resources/integration/v1schema/partials-expected.json +++ b/orca-pipelinetemplate/src/test/resources/integration/v1schema/partials-expected.json @@ -40,5 +40,6 @@ "waitTime": 5 } ], - "notifications": [] + "notifications": [], + "parameterConfig": [] } diff --git a/orca-pipelinetemplate/src/test/resources/integration/v1schema/partialsAndModules-expected.json b/orca-pipelinetemplate/src/test/resources/integration/v1schema/partialsAndModules-expected.json index 1f20129d1e..278d45b8c7 100644 --- a/orca-pipelinetemplate/src/test/resources/integration/v1schema/partialsAndModules-expected.json +++ b/orca-pipelinetemplate/src/test/resources/integration/v1schema/partialsAndModules-expected.json @@ -31,5 +31,6 @@ "waitTime": 5 } ], - "notifications": [] + "notifications": [], + "parameterConfig": [] } diff --git a/orca-pipelinetemplate/src/test/resources/integration/v1schema/simple-expected.json b/orca-pipelinetemplate/src/test/resources/integration/v1schema/simple-expected.json index 2785b08553..c87852b78c 100644 --- a/orca-pipelinetemplate/src/test/resources/integration/v1schema/simple-expected.json +++ b/orca-pipelinetemplate/src/test/resources/integration/v1schema/simple-expected.json @@ -5,5 +5,6 @@ "application": "orca", "name": "Unnamed Execution", "stages": [], - "notifications": [] + "notifications": [], + "parameterConfig": [] } diff --git a/orca-pipelinetemplate/src/test/resources/integration/v1schema/stageInjection-expected.json b/orca-pipelinetemplate/src/test/resources/integration/v1schema/stageInjection-expected.json index 08ee5b89fc..daba0123e4 100644 --- a/orca-pipelinetemplate/src/test/resources/integration/v1schema/stageInjection-expected.json +++ b/orca-pipelinetemplate/src/test/resources/integration/v1schema/stageInjection-expected.json @@ -62,5 +62,6 @@ } ], "id": "unknown", - "notifications": [] + "notifications": [], + "parameterConfig": [] } diff --git a/orca-pipelinetemplate/src/test/resources/integration/v1schema/variableParameters-config.yml b/orca-pipelinetemplate/src/test/resources/integration/v1schema/variableParameters-config.yml new file mode 100644 index 0000000000..1742710540 --- /dev/null +++ b/orca-pipelinetemplate/src/test/resources/integration/v1schema/variableParameters-config.yml @@ -0,0 +1,7 @@ +--- +schema: "1" +pipeline: + application: orca +configuration: + inherit: ['parameters'] +stages: [] diff --git a/orca-pipelinetemplate/src/test/resources/integration/v1schema/variableParameters-expected.json b/orca-pipelinetemplate/src/test/resources/integration/v1schema/variableParameters-expected.json new file mode 100644 index 0000000000..9cce9c0ec9 --- /dev/null +++ b/orca-pipelinetemplate/src/test/resources/integration/v1schema/variableParameters-expected.json @@ -0,0 +1,16 @@ +{ + "id": "unknown", + "keepWaitingPipelines": false, + "limitConcurrent": true, + "application": "orca", + "name": "Unnamed Execution", + "stages": [], + "notifications": [], + "parameterConfig": [ + { + "name": "instances", + "description": "Number of instances to start per region", + "default": 3 + } + ] +} diff --git a/orca-pipelinetemplate/src/test/resources/integration/v1schema/variableParameters-template.yml b/orca-pipelinetemplate/src/test/resources/integration/v1schema/variableParameters-template.yml new file mode 100644 index 0000000000..cdba61c4ea --- /dev/null +++ b/orca-pipelinetemplate/src/test/resources/integration/v1schema/variableParameters-template.yml @@ -0,0 +1,16 @@ +--- +schema: "1" +id: variableParameters +metadata: + name: Variable Parameters + description: Asserts that variables can be used in parameters. +configuration: + parameters: + - name: instances + description: Number of instances to start per region + default: "{{ instances }}" +variables: +- name: instances + description: The number of instances to start per region + defaultValue: 3 +stages: []