如何通过合并分支将TFS拉取请求中的Jenkins作业排队 [英] How to queue Jenkins job from TFS pull request with merged branch

查看:65
本文介绍了如何通过合并分支将TFS拉取请求中的Jenkins作业排队的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在TFS(2017.3)中有一个Git存储库,我们的构建在Jenkins上运行.

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

我们要在拉取请求"中实施构建验证,因此我们创建了一个将Jenkins作业排队的构建定义,并在作业参数"我们进入 BRANCH = $(System.PullRequest.SourceBranch):

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):

问题在于,在TFS的获取源代码"步骤中,TFS创建了一个临时合并的分支来检查PR,但是 System.PullRequest.SourceBranch 返回PR的源分支(例如功能分支),而不是合并分支,因此Jenkins作业在源分支上运行,而不检查PR.

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 (e.g. feature branch) and not the merged branch, so the Jenkins job runs on the source branch and not check the PR.

我们可以将合并后的分支发送给Jenkins,还是必须在Jenkins工作中进行合并?

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

更新:

我看到变量 Build.SourceBranch 返回合并的分支,但看起来就像Jenkins作业不知道该分支.我现在在代理中签入,并且Git在Detached HEAD中,因此我假设没有从代理外部获取的选项(即使该代理创建了一个新分支-合并分支"也仅是本地的).有什么主意吗?

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?

推荐答案

我假设您使用Jenkins TFS插件来触发Jenkins作业.

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

在这种情况下,根据插件官方文档("Git"部分),将 + refs/heads/*:refs/remotes/origin/* + refs/pull/*:refs/remotes/origin-pull/* 添加到Git中的 Refspec 设置中结帐步骤.

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将拉请求合并提交存储在名为 pull/< PR number>/head 的临时分支中.通过添加 Refspec ,您将允许Jenkins提取这些合并提交结果.为我工作.

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.

这篇关于如何通过合并分支将TFS拉取请求中的Jenkins作业排队的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆