Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigger Azure Pipeline on Merge

I have a use case where I have two pipelines configured. One for running tests which are triggered by a Pull Request and another pipeline that is handling deployment. I am using Bitbucket cloud in Azure.

Pipeline A - Run through tests on PR.

Pipeline B - Deploy upon successful merge (approved pull request).

My current setup is to trigger pipeline A when a pull request is submitted. This is no problem and works as intended. The issue I am running into is with Pipeline B. It is triggered regardless of whether the PR is approved or even merged. I know that expected behavior for the CI trigger is to fire off with any action on the branch. The PR trigger also doesn't fit my needs though as it would be redundant with Pipeline A.

What I would like to happen is since Pipeline A fires off on PR, a code reviewer will Approve and Merge the PR and only if the PR ends up getting merged into the Release branch is Pipeline B triggered. Is this possible?

  1. Developer completes code.

  2. Developer submits PR against a Release1.0 branch.

  3. Pipeline A triggers. Tests pass or fail.

  4. Code reviewer approves and merges PR into Release1.0 branch.

  5. Pipeline B triggers and deploys.

like image 224
StormShadow Avatar asked Oct 16 '20 16:10

StormShadow


People also ask

How do you trigger an azure pipeline?

Stages filters for pipeline resource triggers requires Azure DevOps Server 2020 Update 1 or greater. You can trigger your pipeline when one or more stages of the triggering pipeline complete by using the stages filter. If you provide multiple stages, the triggered pipeline runs when all of the listed stages complete.

How do you trigger release pipeline in Azure DevOps?

Select trigger: Set the trigger that will start the deployment to this stage automatically. Select "Release" to deploy to the stage every time a new release is created.

Can GitHub actions trigger the azure pipeline?

GitHub Action to trigger a run in Azure pipelinesWith this action, you could trigger an Azure pipeline run right from inside an Action workflow. The definition of this Github Action is in action. yml.


1 Answers

UPDATE: For those who bump into the same issue it's actually quite a simple fix. Simply setting the trigger...

pr: none

in Pipeline B will do the trick.

To be clear, this solution is specific to Bitbucket Cloud and GitHub repositories only. The 'pr' syntax in YAML pipelines doesn't exist for Azure Repositories (use branch policy instead).

like image 143
StormShadow Avatar answered Sep 27 '22 20:09

StormShadow