title: How to queue Jenkins job from TFS pull request with merged branch
body: <p>We have a Git repository in TFS (2017.3) and our builds run on Jenkins.</p>
  <p>We want to implement in the Pull Request a build validation so we created a build definition that queue a Jenkins job and in the &quot;Job parameters&quot; we enter
  <code>BRANCH=$(System.PullRequest.SourceBranch)</code>:</p>
  <p><a href="https://i.stack.imgur.com/a4CDs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/a4CDs.png" alt="enter image description here" /></a></p>
  <p>The issue is that in the TFS Get Sources step TFS creates a temporarily merged branch to check the PR, but the <code>System.PullRequest.SourceBranch</code> returns the PR source branch (e.g. feature branch) and not the merged branch, so the Jenkins job runs on the source branch and not check the PR.</p>
  <p>Can we send to Jenkins the merged branch or we must to do the merge in the Jenkins job?</p>
  <p><strong>UPDATE:</strong></p>
  <p>I see that the variable <code>Build.SourceBranch</code> returns the merged branch but it looks likes the Jenkins job not know this branch. I checked now in the agent and the Git is in Detached HEAD, so I assume there is no option to get from outside the agent (even if the agent was created a new branch - &quot;merged branch&quot; it's only local). any idea?</p>