Jim Buck
Jim Buck

Reputation: 2444

How do I create a VSTS Build for a Pull Request?

I am trying to create a Build definition in VSTS to run when Pull Requests are made. I have already set up a CI build for the master branch but want to run a separate build on each PR before merging (ideally automatically) into master. I understand branch policies but am having trouble creating the actual Build definition.

When I try to configure the build the Get Sources task requires a branch name, which I don't have when it comes to Pull Requests. How do I create a Build definition just for Pull Requests (where the branch name is unknown)?

Upvotes: 0

Views: 508

Answers (2)

DenverDev
DenverDev

Reputation: 497

This is one of those things that 'just works' without you actually needing to think about it.

  1. Create the build definition that you want to be triggered by the pull request. This can be a specific build for pull requests only, or it can be a build that is multi purpose. You will need to select a branch in the 'Get Sources' step, but VSTS will overwrite this value with a branch that is dynamically created by the pull request
  2. Navigate to Code -> Manage Repositories and follow the instructions to create a Branch Policy. You will want to follow the instructions under 'Require a successful build'
  3. Create a Pull Request from you feature branch to the branch that you configured a policy for in step #2 and you will see that VSTS kicks off a build for you using a dynamically created branch.

Upvotes: 1

Daniel Mann
Daniel Mann

Reputation: 59055

Use Branch Policies. That will allow you to reuse your existing CI build and have it automatically run as part of any PR opened against the specified branch.

Upvotes: 1

Related Questions