I have a multi stage pipeline that has a trigger from another pipeline. If the triggering pipeline is not in the “main” branch I want to skip all prod stages, for example:
- ${{ if value: eq(variables.resources.pipeline.ACP_Server_Build.sourceBranch, 'refs/heads/main') }}:
- stage:....
Is there a way to use the resource sourceBranch in a condition as I described?
If I were using the target pipeline source branch I could do it with the following:
variables:
- name: isMain
value: ${{ eq(parameters.branch, 'main') }}
- ${{ if eq(variables['isMain'], true) }}:
- stage:....
However the documentation shows that the variable: resources.pipeline.resourceName.sourceBranch
is not available as a template variable. If I try to set a variable like this:
- name: resourceBranch
value: $(resources.pipeline.resourceName.sourceBranch)
Then $(resourceBranch)
is available inside a step but also doesn’t work in a template condition. I don’t really want to add a condition:
to each stage because unlike the root level condition, which simply leaves the skipped stages out of the run, adding the condition on each stage individually results in a lot of “Stage Skipped” items in the deployment.