从与当前管道源相同的分支加载 Jenkins 共享库
背景
我有复杂的构建系统,该系统正在运行并使用共享库。管道代码与共享库存储在同一 git 存储库中。两个源都位于 master
分支上。
问题
现在我进行了更大的重构来改进构建和测试过程。因此,我正在开发 feature
分支,并配置了相应的 Jenkins 作业来测试它。
由于我还对共享库引入了更改,所以有一件事情很烦人:要导入库,我必须以这种方式导入该库:
@Library('my_library@feature') _
因此,要将这些更改合并到 master
,我必须更新代码。
有没有办法访问当前管道代码已签出的分支(或其他类型的引用)? 因此,当我合并分支时,共享库将遵循而不更改代码。
我在想这样的事情:
@Library("my_library@${PIPELINE_SOURCE_REF}") _
我搜索文档和互联网,但没有找到这样的东西。
或者有其他解决方案吗?
Background
I have complex build system which is working and uses shared library. Pipelines code is stored in same git repository as shared library. Both sources are on master
branch.
Problem
Now I do larger refactoring to improve build and test process. So I'm working on feature
branch and I configured respective Jenkins job to test it.
Since I introduce changes also to shared library one thing is annoying: to import library I have to import this library this way:
@Library('my_library@feature') _
So to merge this changes to master
I have to update code.
Is there a way to access branch (or other kind of reference) which current pipeline code was checkout?
So when I merge branches shared library follows to without altering code.
I was thinking something like this:
@Library("my_library@${PIPELINE_SOURCE_REF}") _
I search documentation and internet and didn't found anything like this.
Or is there an alternative solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您足以将参数用于库分支,则可以这样做,请查看共享库文档
您需要更改:
为此
,应该加载全局var。
如果您需要实例化某些课程,则可以做类似的事情:
文档中提到的一些局限性,取决于您的图书馆的外观
If it is enough for you to use a parameter for the library branch, it is possible to do so, check out the shared libraries documentation
You would need to change:
to
This should load the global vars.
If you need to instantiate some class, it is possible to do something like:
It has some limitations mentioned in the docs, depends on how your library looks like
在一些非公共存储库中,我在管道前面发现了类似的东西。
尚未测试,但看起来很合理。
scm.branches[0].name
应包含用于签出管道代码的分支名称。On some none public repository I've found something like this in front of the pipeline.
Didn't test it yet, but it seams reasonable.
scm.branches[0].name
should contain name of branch used to checkout pipeline code.