parameters中的参数在sh中是无法直接读取的。所以先通过environment读取,再在sh中使用。

pipeline {
    agent  any
    
    parameters {
        string(name: 'DEPLOY_ENV', defaultValue: 'staging', description: '')
    }

    environment {
        unit_test = "$params.DEPLOY_ENV"
    }
    
    stages {
        stage('Example') {
            steps {
	                script {
	                    sh "echo $unit_test"
	                }
                }
            }
        }
}
Logo

云原生社区为您提供最前沿的新闻资讯和知识内容

更多推荐