问题描述
我们在 TFS (2017.3) 中有一个 Git 存储库,我们的构建在 Jenkins 上运行.
We have a Git repository in TFS (2017.3) and our builds run on Jenkins.
我们希望在 Pull Request 中实现构建验证,因此我们创建了一个构建定义,该定义将 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 enterBRANCH=$(System.PullRequest.SourceBranch)
:
问题是在 TFS Get Sources 步骤中 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 位于分离的 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//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 作业进行排队的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!