I'd like to have the result of a previous stage in a multi-stage pipeline available to me via a variable.
I know that it's possible to use the dependencies object to access the result of a previous stage via the dependency object (see: Expressions in Azure Pipelines).
For example, if I have a previous Stage called "deploy", then I'd be able to access the result as a condition for another stage, like:
condition: in(dependencies.deploy.result, 'Skipped')
This works exactly as intended, however, I'd like to use this variable outside of condition
, i.e. to echo the stage result in a bash task, or add it to a work item description.
However, this does not appear to be possible outside of conditions. If I want to use the result as a variable, or for an if query using the result as condition, it doesn't appear to work. For example the following code block, testString and anotherTestString end up being empty strings:
- stage: afterDeploy
dependsOn:
- deploy
condition: in(dependencies.deploy.result, 'Skipped')
variables:
testString: $[dependencies.deploy.result]
${{ if in(dependencies.deploy.result, 'Skipped') }}:
anotherTestString: "Skipped"
I also tried using different ways to access the variable, i.e. ${{ dependencies.deploy.result }}
, $(dependencies.deploy.result)
, or using stageDependency instead of dependency (stageDependencies.deploy.result
).
Is there a nice way to access the previous stage results directly, or do I have to resort to getting the result via the REST API? Alternatively I could add an extra task exporting the status result as a new variable. Both solutions just don't strike me as optimal, since the stage result is technically available via the dependency object...