Reputation: 175
I have a CI/CD pipeline for a solution with several projects. I check the changes and only build the projects which have been changed, as opposed of building all of them. I accomplish this using a condition at the build stage of each project. This is the relevant part:
- stage: S_BuildChannelUpdate
dependsOn: 'PreSteps'
jobs:
- job: 'BuildChannelUpdate'
variables:
BuildCondition: $[ stageDependencies.PreSteps.Check_changes.outputs['pwsh_script.BuildChannelUpdate'] ]
condition: eq(variables['BuildCondition'], True)
This works as I expect, the build steps are only executed if the conditions are met. So far so good. For the deployment part, I want to do it only if there is something new to be deployed. I.e. project was changed and the build was successful. Again, here is the relevant part:
- stage: 'S_ReleaseChannelUpdate'
dependsOn:
- PreSteps
- S_BuildChannelUpdate
jobs:
- deployment: 'ReleaseChannelUpdate'
variables:
ReleaseCondition: $[ stageDependencies.PreSteps.Check_changes.outputs['pwsh_script.BuildChannelUpdate'] ]
condition: eq(variables['ReleaseCondition'], True)
environment: 'dev'
strategy:
runOnce:
deploy:
steps:
The problem here is that I want to set an approval for the releases and the pipeline asks me to approve it before evaluating the condition. I would like to get the approval request only if the ReleaseCondition is True. I was also expecting that since the stage S_BuildChannelUpdate was skipped (condition not met), the stage S_ReleaseChannelUpdate will consider its dependencies not met.
Any suggestions?
Upvotes: 1
Views: 1650
Reputation: 19471
The problem here is that I want to set an approval for the releases and the pipeline asks me to approve it before evaluating the condition. I would like to get the approval request only if the ReleaseCondition is True
For this issue, here agree with PaulVrugt. Approval is executed at the stage level. Azure Pipelines pauses the execution of a pipeline prior to each stage, and waits for all pending checks to be completed. If the condition is set at the job level, the condition will not be executed before the approval, so as a solution, we need to set the condition at the stage level.
For example:
- stage: 'S_ReleaseChannelUpdate'
dependsOn:
- PreSteps
- S_BuildChannelUpdate
condition: eq(variables['ReleaseCondition'], True)
jobs:
- deployment: 'ReleaseChannelUpdate'
environment: 'dev'
strategy:
runOnce:
deploy:
steps:
With this definition, before executing approval, pipeline will first determine whether ReleaseCondition
is True
, if ReleaseCondition
is False
, then the stage will be skipped
and do not check approval.
- stage: 'S_ReleaseChannelUpdate'
dependsOn:
- S_BuildChannelUpdate
For this, if stage S_BuildChannelUpdate
was skipped (condition not met), the stage S_ReleaseChannelUpdate
will also be skipped
Upvotes: 2