在 Jenkins 声明性管道参数中使用 Jenkins WORKSPACE 环境变量

rok*_*rok 4 environment-variables jenkins jenkins-plugins jenkins-pipeline extended-choice-parameter

有没有办法在 Jenkins 声明性管道参数中使用 Jenkins WORKSPACE 环境变量?

以下尝试失败。

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 { 
   ...
   }
Run Code Online (Sandbox Code Playgroud)

propertyFile: '${WORKSPACE}/templates.properties'也没有用。

Sam*_*tel 7

可以在 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
                }
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)