4

我正忙于集成 Jenkins 和 TFS。我第一次不成功的尝试是使用 Jenkins 的多分支管道设置和 TFS。所以我的第二次尝试是使用带有参数的单个 Jenkins 构建来指定要构建的分支。

我已经调用了这个参数branchRef,并在“要构建的分支”字段中使用它,例如${branchRef}

根据Jenkins 的 Team Foundation Server 插件,我必须按如下方式指定 Refspec:+refs/heads/*:refs/remotes/origin/* +refs/pull/*:refs/remotes/origin-pull/*这将给我一个 ref 列表,例如:

44553f3184c5cbe04e9838209bc752218cd7e54a refs/remotes/origin-pull/563/merge
8bf10538ee29e9df0745ed4b7b23cb20fe56978d refs/remotes/origin/feature/integration
fa8c14671cb6ce1c3ef6dcca52e9e1f45e914e00 refs/remotes/origin/feature/stable

在 TFS 中,我将构建定义设置为使用 Job 参数,例如:branchRef=$(Build.SourceBranch). 在构建分支和拉取请求(合并)时,我得到以下参数:

normal branch: refs/heads/integration
pull-request merge: refs/pull/563/merge

这给出了以下 Jenkins 行为

->normal branch
 > git.exe rev-parse "refs/remotes/origin/integration^{commit}" # timeout=10
->pull-request
 > git.exe rev-parse "refs/pull/563/merge^{commit}" # timeout=10

因此,正常的分支 Jenkins/Git 插件正在从refs/heads/integrationto翻译,refs/remotes/origin/integration而 pull-request 它没有“翻译”。

我已经实施了一种解决方法,即将 Refspec 更改为:+refs/pull/*:refs/pull/* +refs/heads/*:refs/remotes/origin/*但我不知道从长远来看这是否会导致问题。

4

1 回答 1

2

我通过尝试复制您的设置对此进行了测试,并注意到了同样的事情:

因此,正常的分支 Jenkins/Git 插件正在从 refs/heads/integration 转换为 refs/remotes/origin/integration,而 pull-request 它不会“翻译”。

这不应该在它的当前状态下导致任何问题(除非这种令人困惑的行为被改变),因为每次都应该获取遥控器。据我所知,如果您没有进行任何本地更改并被获取,则refs/heads/integration成为无关紧要。refs/remotes/origin/integrationheadsremotes/origin

如果您想绝对确定可以使用以下方法比较它们:(git rev-list --count refs/heads/integration..refs/remotes/origin/integration如果它们相同,则应为 0)。

heads和之间的区别在remotes/origin这里可能是相关的。

于 2018-06-07T00:07:36.783 回答