Spinnaker Pipeline SpEL Expressions: Difference between revisions
(24 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
* https://spinnaker.io/docs/guides/user/pipeline/expressions/ | * https://spinnaker.io/docs/guides/user/pipeline/expressions/ | ||
* https://spinnaker.io/docs/reference/pipeline/expressions/ | * https://spinnaker.io/docs/reference/pipeline/expressions/ | ||
* https://docs.armory.io/armory-enterprise/spinnaker-user-guides/expression-language/ | |||
=Internal= | =Internal= | ||
* [[Spinnaker_Concepts#Pipeline_SpEL_Expressions|Spinnaker Concepts]] | * [[Spinnaker_Concepts#Pipeline_SpEL_Expressions|Spinnaker Concepts]] | ||
* [[Spring Expression Language (SpEL)#Overview|Spring Expression Language (SpEL)]] | |||
=Overview= | =Overview= | ||
The Spinnaker pipeline expression language is based on [[Spring Expression Language (SpEL)#Overview|Spring Expression Language (SpEL)]]. | |||
The pipeline expressions are resolved by default in Kubernetes manifests specified as text. | |||
=Accessing Pipeline Element State= | =Accessing Pipeline Element State= | ||
==A Tag set by a Trigger== | ==A Tag set by a Trigger== | ||
Line 12: | Line 19: | ||
- image: "something/something-else:<font color=teal>${trigger['tag']}</font>" | - image: "something/something-else:<font color=teal>${trigger['tag']}</font>" | ||
</font> | </font> | ||
<font color=darkkhaki>The example above did not work last time I tried it to use it in an artifact specification, but this did:</font> | |||
<syntaxhighlight lang='bash'> | |||
"helm.com/something/something-else-${execution.trigger.parameters.tag}.tgz" | |||
</syntaxhighlight> | |||
For an example where this works see: [[Spinnaker_Concepts#xK2P|Pipeline parameters]]. | |||
==The Judgment Value set by a Manual Judgment Stage== | |||
The value selected by a specific Manual Judgment option can be accessed by subsequent stages with the following expression: | |||
<syntaxhighlight lang='groovy'> | |||
${execution.stages.?[name == '<stage-name>' ][0].context.judgmentInput} | |||
</syntaxhighlight> | |||
The expression can be used in the "Conditional on Expression" clause of subsequent stages as follows: | |||
<syntaxhighlight lang='groovy'> | |||
${execution.stages.?[name == '<stage-name>' ][0].context.judgmentInput == '<option-value>'} | |||
</syntaxhighlight> | |||
where <code>stage-name</code> should be replaced with the actual name of the Manual Judgment stage and <code><option-value></code> with the actual option value using the same capitalization. | |||
An alternative to get the selected option value is to use the <code>${#judgment()</code> function. <font color=darkkhaki>Did not manage to make it work, more experimentation is necessary.</font> For more details see: {{External|https://spinnaker.io/docs/reference/pipeline/expressions/#judgmentstring}} | |||
<syntaxhighlight lang='groovy'> | |||
${#judgment("<stage-name>")} | |||
</syntaxhighlight> | |||
==The Kind and Name of a Manifest Deployed by a Deployment Stage== | |||
<syntaxhighlight lang='groovy'> | |||
${execution.stages.?[name == 'Deploy in Prod'][0].artifacts.reference} | |||
</syntaxhighlight> | |||
==Access an Output Produced by a Run Job (Manifest)== | |||
The output name is "replicas": | |||
<syntaxhighlight lang='groovy'> | |||
${ execution.stages.?[ name == 'Script Job' ][0].outputs.replicas } | |||
</syntaxhighlight> | |||
=Displaying Pipeline State at Runtime= | |||
<font color=darkkhaki>TODO</font> | |||
=Conditional Expressions= | |||
{{External|https://spinnaker.io/docs/reference/pipeline/expressions/#comparisons}} | |||
<syntaxhighlight lang='groovy'> | |||
${ execution.stages.?[ name == 'Rollback Decision' ][0].context.judgmentInput == 'Rollback' } | |||
</syntaxhighlight> | |||
=Variable= | |||
{{Internal|Spinnaker_Pipeline#Pipeline_Variables_2|Pipeline Variables}} |
Latest revision as of 04:33, 31 May 2023
External
- https://spinnaker.io/docs/guides/user/pipeline/expressions/
- https://spinnaker.io/docs/reference/pipeline/expressions/
- https://docs.armory.io/armory-enterprise/spinnaker-user-guides/expression-language/
Internal
Overview
The Spinnaker pipeline expression language is based on Spring Expression Language (SpEL).
The pipeline expressions are resolved by default in Kubernetes manifests specified as text.
Accessing Pipeline Element State
A Tag set by a Trigger
The tag set by a trigger can be accessed with the following expression:
- image: "something/something-else:${trigger['tag']}"
The example above did not work last time I tried it to use it in an artifact specification, but this did:
"helm.com/something/something-else-${execution.trigger.parameters.tag}.tgz"
For an example where this works see: Pipeline parameters.
The Judgment Value set by a Manual Judgment Stage
The value selected by a specific Manual Judgment option can be accessed by subsequent stages with the following expression:
${execution.stages.?[name == '<stage-name>' ][0].context.judgmentInput}
The expression can be used in the "Conditional on Expression" clause of subsequent stages as follows:
${execution.stages.?[name == '<stage-name>' ][0].context.judgmentInput == '<option-value>'}
where stage-name
should be replaced with the actual name of the Manual Judgment stage and <option-value>
with the actual option value using the same capitalization.
An alternative to get the selected option value is to use the ${#judgment()
function. Did not manage to make it work, more experimentation is necessary. For more details see:
${#judgment("<stage-name>")}
The Kind and Name of a Manifest Deployed by a Deployment Stage
${execution.stages.?[name == 'Deploy in Prod'][0].artifacts.reference}
Access an Output Produced by a Run Job (Manifest)
The output name is "replicas":
${ execution.stages.?[ name == 'Script Job' ][0].outputs.replicas }
Displaying Pipeline State at Runtime
TODO
Conditional Expressions
${ execution.stages.?[ name == 'Rollback Decision' ][0].context.judgmentInput == 'Rollback' }