[英]Use Jenkins WORKSPACE environment variable in Jenkins declarative pipeline parameter
Is there a way to use Jenkins WORKSPACE environment variable in Jenkins declarative pipeline parameters?有没有办法在 Jenkins 声明性管道参数中使用 Jenkins WORKSPACE 环境变量?
Below attempt failed.以下尝试失败。
pipeline {
parameters {
extendedChoice description: 'Template in project',
multiSelectDelimiter: ',', name: 'TEMPLATE',
propertyFile: env.WORKSPACE + '/templates.properties',
quoteValue: false, saveJSONParameterToFile: false, type: 'PT_MULTI_LEVEL_SINGLE_SELECT',
value: 'Project,Template', visibleItemCount: 6
...
}
stages {
...
}
propertyFile: '${WORKSPACE}/templates.properties'
didn't work either. propertyFile: '${WORKSPACE}/templates.properties'
也不起作用。
The environment variable can be accessed in various place in Jenkinsfile like:可以在 Jenkinsfile 中的各个位置访问环境变量,例如:
def workspace
node {
workspace = env.WORKSPACE
}
pipeline {
agent any;
parameters {
string(name: 'JENKINS_WORKSPACE', defaultValue: workspace, description: 'Jenkins WORKSPACE')
}
stages {
stage('access env variable') {
steps {
// in groovy
echo "${env.WORKSPACE}"
//in shell
sh 'echo $WORKSPACE'
// in groovy script
script {
print env.WORKSPACE
}
}
}
}
}
The only way that worked is putting absolute path to Jenkins master workspace where properties file is located.唯一可行的方法是将绝对路径放置到属性文件所在的 Jenkins 主工作区。
pipeline {
parameters {
extendedChoice description: 'Template in project',
multiSelectDelimiter: ',', name: 'TEMPLATE',
propertyFile: 'absolute_path_to_master_workspace/templates.properties',
quoteValue: false, saveJSONParameterToFile: false, type: 'PT_MULTI_LEVEL_SINGLE_SELECT',
value: 'Project,Template', visibleItemCount: 6
...
}
stages {
...
}
It seems that environment variables are not available during pipeline parameters definition before the pipeline actually triggered.在管道实际触发之前,在管道参数定义期间似乎环境变量不可用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.