21
votes

My git repo is hosted inside devops and I would like the code to be built and tests run when I create a pull request. However I can't see how to do this. I read about pull request triggers etc but I can not see how to add these as no option appear to create them.

Once the pull request is completed and it merges to master I have a pipeline that builds and tests that code etc but I also want this to happen before anyone can complete a pull request.

2

2 Answers

26
votes

How do I trigger build and test on a pull request in azure devops?

Build validation should be exactly what you are looking for.

Set a policy requiring changes in a pull request to build successfully with the protected branch before the pull request can be completed. Build policies reduce breaks and keep your test results passing. Build policies help even if you're using continuous integration (CI) on your development branches to catch problems early.

enter image description here

With this setting, once you initiate a PR on the target branch, the Build validation will trigger the build pipeline that you set, only after the build is successful, the PR will be allowed to complete.

Hope this helps.

2
votes

On main page of Azure DevOps go to Repos -> Branches -> (for example) master -> Branch Policies

You can link here build that will that will need to end successfully before you will be able to merge new changes to your branch by pull request.

enter image description here