【问题标题】:Jenkins Git Refspec not correctly substituted for branch specifierJenkins Git Refspec 未正确替换分支说明符
【发布时间】:2018-11-11 10:18:03
【问题描述】:

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

我已将此参数称为 branchRef 并在“要构建的分支”字段中使用它,例如 ${branchRef}

根据Team Foundation Server plugin for Jenkins,我必须按如下方式指定 Refspec:+refs/heads/*:refs/remotes/origin/* +refs/pull/*:refs/remotes/origin-pull/* 这会给我一个参考列表,例如:

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

在 TFS 中,我已将构建定义设置为使用作业参数,例如: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/integration 转换为 refs/remotes/origin/integration,而 pull-request 它并没有“翻译”。

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

【问题讨论】:

  • 您目前的解决方法是否遇到任何问题?只需监控它,如果没有问题,这应该是一个很好的解决方法。

标签: git jenkins tfs


【解决方案1】:

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

所以正常分支 Jenkins/Git 插件是从 refs/heads/integration 到 refs/remotes/origin/integration 而 拉取请求它不会“翻译”。

这不会导致当前状态出现任何问题(除非改变了这种令人困惑的行为),因为每次都应该获取遥控器。据我所知,如果您没有对headsremotes/origin 进行任何本地更改,那么refs/heads/integration 变为refs/remotes/origin/integration 是无关紧要的。

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

The difference between heads and remotes/origin 可能与此处相关。

【讨论】:

  • 到目前为止我还没有遇到问题。但我也不是一个伟大的 Git 大师。
  • @DaanTimmer 您应该不会遇到任何问题,正如我在答案中解释的那样,在您的情况下两者应该是相同的。
猜你喜欢
  • 2017-01-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-25
  • 1970-01-01
  • 2015-10-19
  • 1970-01-01
相关资源
最近更新 更多