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

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐