Reputation: 201
I have two yaml files; one is for the CI.yml pipeline, and another is for the CD.yml pipeline
The current setup is for every successful CI.yml build; the CD.yml will trigger afterwards.
This is the code/config of my CD.yml:
trigger: none
resources:
pipelines:
- pipeline: CI
source: "CI"
trigger:
branches:
include:
- main
exclude:
- '*'
stages:
- 'Package: CI'
I need to set up a pull request build validation for CI.yml main branch. The issue is whenever there is a pull request, and the CI.yml completes its build validation pull request. It also triggers the CD.yml, which I don't want, is there any other way to exclude the PR in the CD trigger? It seems that the 'pr' is an unknown property under 'pipelines:' and the stage filter is not working since I already set that if the build_reason = pull request, the 'Package: CI' will be skipped. The exclusion of all branches ('*') also doesn't work.
Upvotes: 0
Views: 1286
Reputation: 2978
If wanting to keep your pipelines separated then one approach would be to set the trigger for the CI pipeline to none and have it triggered via the build validation on branch policy in ADO.
This would then be triggered anytime someone is merging into the main branch. Remove the pipeline dependency on the CD pipeline set the trigger to the main branch. The workflow then would be CI triggered as a build validation anytime there is a request to merge into main and CD to run after the merge into main.
An alternative that I would actually recommend is to leverage one .yml pipeline file for both the CI and the CD.
This would look something like: stages:
- template: stages/adf_build_stage.yml@templates
parameters:
serviceName: ${{ parameters.serviceName }}
- ${{ if eq(variables['Build.SourceBranch'], 'refs/heads/main')}}:
- template: stages/adf_deploy_stage.yml@templates
parameters:
environmentObjects: ${{ parameters.environmentObjects }}
serviceName: ${{ parameters.serviceName }}
The azure devops expression can have other criteria. The jist of this is the same steps you are executiong for your CI should be the first steps of your CD. (i.e. build, code scanning, publishing the artifact) so why not combine them and conditionally run the deployment. This will lead to a reduction in maintaining multiple pipelines. Just ensure you have something in place to consider pipeline retention since the same pipeline will be used for CI and deployments.
Upvotes: 0