环境变量的使用 我们有两种获取价值的方法.由于Groovy与Java的紧密关系,在启动过程中-D=传递的属性我们可以理解为System.getProperty("key"). Usage of environment variables We have two ways to get their value. The properties passed by -D= during the startup we could read as System.getProperty("key") thanks to the Groovy's strong relation with Java.以Java方式读取普通环境变量是System.getenv("VARIABLE") ...Reading normal environment variables in Java way is the System.getenv("VARIABLE")...让我们尝试一下:println "JOB_NAME = " + System.getenv('JOB_NAME');现在,我得到了:java.lang.NullPointerException: Cannot get property 'System' on null object空对象?但是,我看到JOB_NAME是一个环境变量!Null object? But, I can see that JOB_NAME is an environment variable!如何在管道作业中将$JOB_NAME读入DSL脚本中.我正在尝试管道作业,当我获得该工作时,将使它成为具有Jenkinsfile的多分支管道.How do I read in the $JOB_NAME into a DSL script in a Pipeline job. I am trying a Pipeline job, and when I get that working will make this a Multibranch Pipeline with a Jenkinsfile.推荐答案所有环境变量均可使用env访问,例如${env.JOB_NAME}.All environment variables are accessible using env, e.g. ${env.JOB_NAME}. 这篇关于Jenkins Pipeline访问环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-31 14:44