[英]Get an environment variable by name in Jenkins
I'm using Jenkins Template Engine and I'm facing the following issue:我正在使用 Jenkins 模板引擎,但面临以下问题:
Let's say I want to have a library step that uploads artifacts to Artifactory.假设我想要一个将工件上传到 Artifactory 的库步骤。 This step should set as a property the URL of the git commit.
这一步应该将 git commit 的 URL 设置为一个属性。 I want that each project will provide this URL in a
pipeline_config.groovy
file, not hard-coded in the step.我希望每个项目都在
pipeline_config.groovy
文件中提供此 URL,而不是在步骤中进行硬编码。
The thing is, that this URL is composed of some fixed string, plus a dynamic value, namely env.GIT_COMMIT
: eg: http://specific-server.com/project/${env.GIT_COMMIT}
问题是,这个 URL 由一些固定字符串和一个动态值组成,即
env.GIT_COMMIT
:例如: http://specific-server.com/project/${env.GIT_COMMIT}
: env.GIT_COMMIT
http://specific-server.com/project/${env.GIT_COMMIT}
Eventually, I want the step to be as follows:最后,我希望步骤如下:
// upload.groovy
def call() {
def props = config.git_url
}
and the pipeline_config file:和 pipeline_config 文件:
// pipeline_config.groovy
libraries {
artifactory
{
git_url = "http://specific-server/project/${env.GIT_COMMIT}"
}
}
So the question comes down to this: How can I instruct the library step to retreive some dynamic variable from the pipeline_config.groovy file?所以问题归结为:如何指示库步骤从 pipeline_config.groovy 文件中检索一些动态变量?
@steven-terrana @史蒂文-特拉纳
JTE can resolve the env
var within the pipeline configuration, assuming the environment has been set for the build. JTE 可以解析管道配置中的
env
var,假设已经为构建设置了环境。
If the GIT_COMMIT comes from the project being built, you could determine that information from within the library step using the git cli and then concatenate the base-url provided from the pipeline configuration.如果 GIT_COMMIT 来自正在构建的项目,您可以使用 git cli 从库步骤中确定该信息,然后连接从管道配置提供的 base-url。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.