如何在Jenkinsfile中调用全局环境变量?
例如,如果我有一个变量-
name:credentialsId
value:xxxx-xxxx-xxxxx-xxxxxxxxx
如何在groovy脚本中使用它?
我尝试了
${credentialsId}
,但是没有用。它只会给出错误:java.lang.NoSuchMethodError: No such DSL method '$' found among steps [ArtifactoryGradleBuild, ........
最佳答案
在Jenkinsfile中,您具有“Working with the Environment”,其中提到:
语法为${env.xxx}
,如下所示:
node {
echo "Running ${env.BUILD_ID} on ${env.JENKINS_URL}"
}
另请参见“Managing the Environment”。Jenkins -> Manage Jenkins -> Configure System -> Global properties -> Environment variables
参见“Setting environment variables”node {
/* .. snip .. */
withEnv(["NAME=value"]) {
... your job
}
}
关于jenkins - Jenkinsfile中的Jenkins全局环境变量,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41235165/