在 Jenkins 作业 DSL 中访问 ENV_INJECT 个变量
access ENV_INJECT variables in Jenkins job DSL
我无法访问 JobDSL 的 groovy 脚本中的任何 Jenkins 环境变量。我可以看到系统环境变量的值。
这是 groovy 脚本 我是 运行:
println(System.getenv("HOME"))
println(System.getenv("WORKSPACE"))
这是输出:
/users/s051464
null
我试过使用环境注入设置环境变量,但也不起作用(所有设置变量均为空)。
您应该可以使用 ${VAR_NAME}
、more info here. One exception is node specific variables such as WORKSPACE
, in those cases you need to do the following (from here):
hudson.FilePath workspace = hudson.model.Executor.currentExecutor().getCurrentWorkspace()
我无法访问 JobDSL 的 groovy 脚本中的任何 Jenkins 环境变量。我可以看到系统环境变量的值。
这是 groovy 脚本 我是 运行:
println(System.getenv("HOME"))
println(System.getenv("WORKSPACE"))
这是输出:
/users/s051464
null
我试过使用环境注入设置环境变量,但也不起作用(所有设置变量均为空)。
您应该可以使用 ${VAR_NAME}
、more info here. One exception is node specific variables such as WORKSPACE
, in those cases you need to do the following (from here):
hudson.FilePath workspace = hudson.model.Executor.currentExecutor().getCurrentWorkspace()