azure-devopsazure-pipelines

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


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.


Solution

  • 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.