AnotherHowie
AnotherHowie

Reputation: 822

Azure Devops - trigger pipeline on Pull Request but not Push?

I have a ADO git repo with a YAML-based build pipeline that builds a docker image, runs some tests using Docker Compose, and then pushes the image and a helm chart to an ACR.

I'd like the have the build/test part run on PRs too. I have created a second pipeline that's just the first half of the normal build, and assigned it as a Build Validation pipeline for a branch.

However, I don't seem to be able to get the triggers right. If I have trigger: none in the test pipeline, it never triggers. If I have branch names, it is also run on merge alongside the normal build pipeline. How is this supposed to work? The docs define all the individual parts, but not really how they are expected to interact!

Am I supposed to have a multistage pipeline and use that somehow for the validation? (it's just 4 Steps in one Job in one Stage currently).

I am hoping to avoid building the same image too many times, or storing untested images anywhere outside the build agent.

Upvotes: 1

Views: 3925

Answers (1)

Jane Ma-MSFT
Jane Ma-MSFT

Reputation: 5242

I make it work with the following configuration:

In my YAML pipeline, I set the trigger: none.

In branch policies of a branch, I create a build validation with automatic trigger: enter image description here

Then I create a pull request to that branch, and the pipeline runs automatically: enter image description here

There are two possible mistakes:

  1. The "Manual" trigger is selected in build validation, so that the pipeline needs to be run manually rather than triggered automatically.
  2. The branch with branch policy set should be the same branch as the target branch of pull request.

Upvotes: 2

Related Questions