使用 Git SCM 设置全局管道库时 ${library.pipeline-utils.version} 放在哪里

Where to put ${library.pipeline-utils.version} when using Git SCM to setup Global Pipeline Library

我正在尝试设置一个全局管道库,它将根据 these instruction 使用 @Library() 显式加载。关于从 master 分支加载默认库版本,我可以正常工作。

我无法做的是弄清楚如何配置事物,以便它可以使用 Library('lib-name@branch-name') 语法根据请求加载不同的分支。

说明说:

"When using Legacy SCM, you will need to include ${library.pipeline-utils.version} in the SCM configuration somewhere."

我试过使用 ${library.pipeline-utils.version} 作为 Branch Specifier 的值,这是我认为放置它的唯一合乎逻辑的地方。但这只会破坏事情。尝试加载库失败:

Fetching upstream changes from ssh://git@stash:7999/jen/pipeline-utils.git
 > git --version # timeout=10
 > git fetch --tags --progress ssh://git@stash:7999/jen/pipeline-utils.git +refs/heads/*:refs/remotes/origin/*
 > git rev-parse refs/remotes/origin/${library.pipeline-utils.version}^{commit} # timeout=10
 > git rev-parse refs/remotes/origin/origin/${library.pipeline-utils.version}^{commit} # timeout=10
 > git rev-parse origin/${library.pipeline-utils.version}^{commit} # timeout=10
ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.

这让我觉得我把变量放在了正确的位置,但 Jenkins 没有插入它。 (错误?)

这是使用 Jenkins 2.7.1 和管道版本 2.4

我是这样设置的,使用版本变量 ${library.CpsGlobal.version}Branches to build / Branch Specifier :

ps。请从库名称中删除“-”字符,因为 Groovy 不支持它。

为我工作:

  • 库名:testlib
  • 默认版本:分支名称
  • 要构建的分支:${library.testlib.version}

现在终于有了 Git 的 'modern scm' 实现,我们正在使用它。