title: How to CI build branches in VSTS
body: <p>We use Git repositories in <strong>VSTS</strong> with branches and <strong>Pull Requests</strong> model to allow Code Reviews.</p>
  
  <p>We have a <strong>CI Build</strong> definition and following it <strong>Release</strong> definition for all commits pushed to master.</p>
  
  <p>And it would be a huge bonus if we can do <strong>CI for all branches</strong> too.
  However Build definition for Git repos allows to setup only single branch to track.</p>
  
  <p>And creating a Build per branch isn't feasible, as our branches are short-living aka feature branches and we delete them after PR merge to master.</p>
  
  <p>Yes, there is an ability to specify to run <strong>CI build for PRs</strong> to master in <strong>Branch Policies</strong> page. But there are 2 issues with this:</p>
  
  <ul>
  <li><p>this will build only PR, while we want to build all the individual commits in branches as soon as they are pushed there</p></li>
  <li><p>CI build for PRs will trigger our Release too, but we obviously want it to be triggered only for master builds. Yes I can analyze <code>$(Build.SourceBranch)</code> or <code>$(Build.SourceBranchName)</code> in the Release definition and fail if it's not "master" but it will create a failed Release anyway, which I just want to avoid at all</p></li>
  </ul>
  
  <p>So... how can we have CI builds in VSTS for any arbitrary branch?</p>
  
  <hr>
  
  <h2>Update</h2>
  
  <p>Another idea wrt running Release only for master builds - is to trigger Release from the Build side, e.g. <a href="https://www.visualstudio.com/en-us/docs/integrate/api/rm/releases#create-a-release" rel="nofollow">by using API</a> if <code>$(Build.SourceBranch)</code> equals to 'master', say by custom PowerShell script.</p>
  
  <p>I can see there's even an extension for <a href="https://marketplace.visualstudio.com/items?itemName=sergiibomko.vsts-trigger" rel="nofollow">VSTS Trigger build step</a>, but it will trigger even for non-master builds, although Microsoft is working on <a href="https://visualstudio.uservoice.com/forums/330519-team-services/suggestions/8623600-allow-build-vnext-preview-tasks-to-be-conditionall" rel="nofollow">a feature to run steps conditionally</a>.</p>