简体   繁体   中英

How to queue Jenkins job from TFS pull request with merged branch

We have a Git repository in TFS (2017.3) and our builds run on Jenkins.

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 "Job parameters" we enter BRANCH=$(System.PullRequest.SourceBranch) :

在此处输入图片说明

The issue is that in the TFS Get Sources step TFS creates a temporarily merged branch to check the PR, but the System.PullRequest.SourceBranch returns the PR source branch (eg feature branch) and not the merged branch, so the Jenkins job runs on the source branch and not check the PR.

Can we send to Jenkins the merged branch or we must to do the merge in the Jenkins job?

UPDATE:

I see that the variable Build.SourceBranch 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 - "merged branch" it's only local). any idea?

I assume you use Jenkins TFS plugin to trigger a Jenkins job.

In that case according to plugin official documentation (section 'Git') you need to add +refs/heads/*:refs/remotes/origin/* +refs/pull/*:refs/remotes/origin-pull/* to Refspec setting in Git Checkout step.

TFS stores pull request merge commits in temporary branches named pull/<PR number>/head . By adding Refspec you'll allow Jenkins to fetch these merge commit results. Works for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM