My team and I are struggling to implement a particular CI/CD pattern in ADO.
We have defined a Build Pipeline called "Develop" and a Release Pipeline with the same name. We have set a Build Policy on our development branch that requires the "Develop" Build Pipeline succeeds before the PR can be completed. We also have policies for reviews/approvals, comment resolution, and linked work items.
As expected, when a PR is raised, the build referenced in our policy is kicked off. Also as expected, the PR cannot be completed until that build succeeds. The problem we had, though, was that because we had a CD trigger set up on the Release Pipeline, the artifacts generated by the PR-triggered build would always get deployed, regardless of the status of the rest of the PR policies.
The sequence we want is this:
- Raising a PR causes our "Develop" Build Pipeline to execute.
- This build must succeed before the PR can be completed.
- This build's artifacts are stored such that the Build Pipeline does not have to run again after the PR is completed, just to do the deployment (the build takes a while).
- The Build Pipeline successfully executes.
- The PR still cannot be completed until other policies are satisfied.
- The remaining branch policies are satisfied.
- The PR is completed.
- Only now can the artifacts generated from the Build Pipeline be deployed.
- The "Develop" Release Pipeline is executed, deploying the artifacts to our testing environment.
After fiddling around with variations of our Pipelines, I tried simply setting the "Pull request trigger" instead of the "Continuous deployment trigger" on the Release Pipeline. I assumed this would require that a PR had resulted in the creation of artifacts, and the PR completed. My assumption was incorrect. With this new setup, raising the PR triggers the Build Pipeline, and success of the Build Pipeline triggers the Release Pipeline, even if the PR has not yet been completed.
Our Build Pipeline builds the solution, runs tests, runs some PowerShell scripts, and finally publishes artifacts to Azure Pipelines. Perhaps this is doing too much. Perhaps there is some way to build, run the tests and scripts, and then somehow wait for the PR to complete before passing the artifacts along to the Release Pipeline. I just can't seem to figure it out. Is there any way to accomplish the sequence I listed above?
Requirements, in a nutshell:
- The build should start as soon as the PR is raised.
- The build should not have to execute more than once (it takes a long time, and we can't wait for two builds just to satisfy a build policy before the "real" build).
- The PR completion should trigger the Release Pipeline.