Jenkins Pipeline 中的环境变量 [英] Environment variable in Jenkins Pipeline

查看:92
本文介绍了Jenkins Pipeline 中的环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何环境变量可用于获取 Jenkins Pipeline Title?

Is there any environment variable available for getting the Jenkins Pipeline Title?

我知道我们可以使用 $JOB_NAME 来获得自由式工作的头衔,但是有什么可以用来获取管道名称的吗?

I know we can use $JOB_NAME to get title for a freestyle job, but is there anything that can be used for getting Pipeline name?

推荐答案

您可以使用相同的名称从 groovy 访问相同的环境变量(例如 JOB_NAMEenv.JOB_NAME).

You can access the same environment variables from groovy using the same names (e.g. JOB_NAME or env.JOB_NAME).

来自文档:

可以从 Groovy 代码中以 env.VARNAME 或简单地以 VARNAME 的形式访问环境变量.您也可以写入此类属性(仅使用 env. 前缀):

Environment variables are accessible from Groovy code as env.VARNAME or simply as VARNAME. You can write to such properties as well (only using the env. prefix):

env.MYTOOL_VERSION = '1.33'
node {
  sh '/usr/local/mytool-$MYTOOL_VERSION/bin/start'
}

这些定义也将在构建期间或完成后通过 REST API 以及使用构建步骤从上游管道构建中获得.

These definitions will also be available via the REST API during the build or after its completion, and from upstream Pipeline builds using the build step.

对于文档的其余部分,单击任何管道作业中的管道语法"链接

For the rest of the documentation, click the "Pipeline Syntax" link from any Pipeline job

这篇关于Jenkins Pipeline 中的环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆