docker - 如何将共享库的分支名称指定为环境变量
问题描述
我想引用/指定(语法)分支,该分支设置为 Jenkins 共享库的环境变量,它将在 docker 容器期间提供。例如:
@Library(['my-shared-library', BRANCH_NAME])
尝试使用 ${BRANCH_NAME} ${env.BRANCH_NAME}
我将在 docker-compose.yml 中提供 BRANCH_NAME 作为环境变量
我也想在 org.jenkinsci.plugins.workflow.libs.GlobalLibraries.xml 中获得 env 变量
就像我将 PIPELINE_VERSION 设置为 env 变量
<?xml version='1.1' encoding='UTF-8'?>
<org.jenkinsci.plugins.workflow.libs.GlobalLibraries plugin="workflow-cps-global-lib@2.15">
<libraries>
<org.jenkinsci.plugins.workflow.libs.LibraryConfiguration>
<name>XXXXXXXXXXXX</name>
<retriever class="org.jenkinsci.plugins.workflow.libs.SCMSourceRetriever">
<scm class="jenkins.plugins.git.GitSCMSource" plugin="git@3.12.0">
<id>XXXXXXXXXXXXXXXXXXXXXXXX</id>
<remote>XXXXXXXXXXXXXXXXXXX</remote>
<credentialsId>jXXXXXXXXXXXXXXXXXXXX</credentialsId>
<traits>
<jenkins.plugins.git.traits.BranchDiscoveryTrait/>
</traits>
</scm>
</retriever>
<defaultVersion>${PIPELINE_RELEASE_VERSION}</defaultVersion>
<implicit>true</implicit>
<allowVersionOverride>true</allowVersionOverride>
<includeInChangesets>false</includeInChangesets>
</org.jenkinsci.plugins.workflow.libs.LibraryConfiguration>
</libraries>
</org.jenkinsci.plugins.workflow.libs.GlobalLibraries>
谢谢, Kusuma
解决方案
无论如何,我认为不可能使环境变量可用于 org.jenkinsci.plugins.workflow.libs.GlobalLibraries.xml。但是,如果您使用Jenkins 代码作为配置插件,您可以从 docker-compose 传递变量并将其提供给配置文件,并且当 Jenkins 加载配置文件为 Jenkins 准备配置时将起作用。一个例子可以在这里找到
推荐阅读
- java - 在 Tomcat 上部署为 WAR 的 Spring Boot 应用程序中增加类加载计数
- sql - Athena 中的 cast 和 left 函数
- vb.net - 如何将来自 vb.net 中的压机的中间数字转换为帐号形式的星号
- excel - VBA 检查特定列中的每一行
- python - 用鼠标悬停时用 matplotlib 注释绘图的线条
- mysql - 需要优化的 mysql 查询
- rust - 如何在用户不输入 sudo 的情况下停止程序并使用 sudo 重新启动?
- python-3.x - 将数据导入 python IBM watson Studio 后收到警告消息
- angular - 如何在Angular的另一个模块中更改组件的模型?
- python - 使用 Python 一次性从邮件附件中提取 ZIP 文件中的 CSV 文件