简体   繁体   English

如何引用 jenkins 共享库特定分支

[英]How to refer a jenkins shared library specific branch

I have a repository for a jenkins shared library named "jenkins-shared-library" , now I created a new branch called "test",我有一个名为“jenkins-shared-library”的 jenkins 共享库的存储库,现在我创建了一个名为“test”的新分支,

I have an application that need to use this jenkins shared library inside a jenkins file, currently it is being referred as我有一个应用程序需要在 jenkins 文件中使用这个 jenkins 共享库,目前它被称为

@Library('jenkins-shared-library')_

I want to use this specific test branch of my jenkins-shared-library inside my jenkinsfile, how can I use the specific branch of jenkins-shared-library???我想在我的 jenkinsfile 中使用 jenkins-shared-library 的这个特定测试分支,我该如何使用 jenkins-shared-library 的特定分支???

Take a look at the Shared Libraries Documentation , there are several ways to control the version of a shared library across the pipelines.查看共享库文档,有多种方法可以跨管道控制共享库的版本。

First option is to define the version in Global Pipeline Libraries configuration - which will affect all the pipelines that are using that library.第一个选项是在全局管道库配置中定义版本 - 这将影响使用该库的所有管道。

The second option, which is probably what you need is to use the version specifier when loading the library, the format will be @Library('my-shared-library@<BranchName>') .第二个选项,这可能是你需要的是在加载库时使用版本说明符,格式将是@Library('my-shared-library@<BranchName>') The version specifier can be a branch name, a git tag and so.版本说明符可以是分支名称、git 标签等。

// Using a version specifier, such as branch, tag, etc
@Library('my-shared-library@1.0') _
// Accessing multiple libraries with one statement 
@Library(['my-shared-library', 'otherlib@abc1234']) _

Important If you want to override the version of a default library defined in the in Global Pipeline Libraries you must enable the Allow default version to be overridden in the Shared Library's configuration - or else you wont be able to use a custom version.重要如果您想覆盖在全局管道库中定义的默认库的版本,您必须在共享库的配置中启用允许覆盖默认版本- 否则您将无法使用自定义版本。

When loading libraries dynamically (using the library step) you can also specify a version: library 'my-shared-library@master' , and since this is a regular step, the version could be computed at runtime rather than just using a constant value as with the annotation.动态加载库时(使用library步骤),您还可以指定版本: library 'my-shared-library@master' ,由于这是常规步骤,因此可以在运行时计算版本,而不仅仅是使用常量值和注释一样。
for example: library "my-shared-library@$BRANCH_NAME"例如: library "my-shared-library@$BRANCH_NAME"

您可以简单地通过将其声明为“测试”分支来使用它

@Library('jenkins-shared-library@test')_

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM