11
votes

I have a repo which has two branches:

  • develop (repo's default branch)
  • master

Code within the develop branch is known to be releasable as an "alpha" version, while code within master is known to be production ready.

Currently, the develop branch's policies requires that a CI build must successfully complete for the PR to merge. That build will create NuGet package artifacts with a prerelease tag (alpha-####).

A release pipeline is responsible for taking these packages and publishing them to an internal NuGet feed.

What I'm trying to achieve is to have the release pipeline triggered automatically when the PR is completed, not whenever the CI build succeeds.

I expected the "pull request trigger" to do just that, but much to my surprise the trigger won't acknowledge the PR's status and have the release pipeline start as soon as the CI build is completed.

This means that if the PR gets rejected for whatever reason, a NuGet may still be deployed to my feed!

What am I doing wrong here? How come the pull request trigger doesn't work any differently than the continuous deployment trigger? What's it's purpose then? :/

2
Have the merge trigger a build. Have the build trigger a release.Daniel Mann
@DanielMann by merge you mean PR? Because I tried that already. The PR will cause the build to launch but I need the release to happen on the condition that the PR has been completed.Crono
@DanielMann So I've put my brain back on this morning and I now understand you meant having a build definition with a CI trigger on the develop branch. That would work, of course. I just hate having to wait up for one more build (along with branch policy build) before a release can happen.Crono

2 Answers

6
votes

The continuous deployment trigger means, if you specify certain types of artifacts in a release pipeline, you can enable continuous deployment. This instructs Azure Pipeline to create new releases automatically when it detects new artifacts are available.

The Pull request trigger means, once a pull request release is configured, anytime a pull request is raised for the protected branch, a release is triggered automatically, deployed to the specified environments.

So these two triggers are different and more detailed information you can refer to here. https://docs.microsoft.com/en-us/azure/devops/pipelines/release/deploy-pull-request-builds?view=azure-devops

https://docs.microsoft.com/en-us/azure/devops/pipelines/release/triggers?view=azure-devops

And if you still want to deploy your Nuget after a PR completed, I recommend you to create a new build pipeline and enable the Continuous integration for it. Then set this build pipeline as the Release pipeline Artifact. Because when a PR completed, it will create a new commit to the target branch and this new commit will trigger the build pipeline, and the build pipeline will trigger the release pipeline to deploy the Nuget as your expected.

2
votes

Not sure if anyone's still looking for a solution to this over a year after the fact, but I was so I wrote an Azure Function app to receive pull request close webhooks from DevOps and translate those events into new releases.

You can find it here on my github: https://github.com/GravlLift/OnPullRequest

Feel free to fork it to fit whatever your individual needs are.