I have a pipeline (MainPipeline) which triggers another one (DependantPipeline).
I want to have some basic task done in main pipeline (Build and Test stage) which are common for any triggered pipeline. So far triggering works as expected which means that MainPipeline triggers the DependantPipeline, however the DependantPipeline skips all stages based on my last changes (Build and Test stage and DEV stage). It should skip only Build and Test stage and let continue DEV stage.
My goal is to skip only Build and Test stage and run Dev stage at DependantPipeline. On the other hand, Build stage must work only (and pass) on MainPipeline (which in fact does). The issue is later, on DependantPipeline and the condition as I believe.
/templates/pipeline.yml@Pipelines
stages:
- stage: Build
displayName: Build
condition: and(succeeded(), not(${{parameters.skipBuildAndTest}}))
/templates/deployment.yml@Pipelines
stages:
- ${{ if ne(parameters.devEnvironment, '') }}:
- stage: DEV
displayName: DEV Environment
# dependsOn: Build
condition: succeeded()
With many attempts I am not able to achieve the desired effect.
I download log from Azure DevOps, so maybe it will be helpful. Logs says at Build stage:
stages:
- stage: Build
displayName: Build
condition: and(succeeded(), not(true))
Also at DEV stage it says:
- stage: DEV
displayName: DEV Environment
condition: succeeded()
Yes, your issue is being caused by your conditions.
The Build stage is being skipped because you've set the skipBuildAndTest: true
, which negates the defined condition and( true, not(true) )
.
The Deploy_DEV stage is being skipped because you've specified that the previous stage must be successful: condition: succeeded()
. This is actually the default value.
Note that in a multi-stage pipeline with no dependencies between stages, it is assumed that the stages are sequential and therefore dependent on each other. Because the Build stage was skipped, the Deploy_DEV stage is skipped as well.
If you want to evaluate the outcome of the previous stage, you need to explicitly define the relationship so you can programmatically use it.
- stage: Deploy_DEV
dependsOn:
- Build
condition: in( dependencies.Build.result, 'Succeeded', 'Skipped', '')
...
In the above, we're checking whether it was either Succeeded or Skipped. The condition to check for '' is to handle the edge-case when the pipeline is manually queued and the stage is deselected.