0

如何访问块SOME_VAR内的现有环境变量environment

我想用新名称重新定义它NEW_VAR

pipeline {
    agent {
        label any
    }
    environment {
        SECRET = credentials('secret-credential') // works as expected
        NEW_VAR = ? // get from different env variable
    }
    stages {
        stage('Test') {
            steps {
                echo "SECRET=${env.SECRET}"
                echo "NEW_VAR=${env.NEW_VAR}"
            }
        }
    }
}

到目前为止我尝试了什么:

NEW_VAR = SOME_VAR        // fails build
NEW_VAR = env.SOME_VAR    // fails build
NEW_VAR = ${env.SOME_VAR} // fails build
NEW_VAR = env('SOME_VAR') // does not fail, but NEW_VAR is null
NEW_VAR = env(SOME_VAR)   // does not fail, but NEW_VAR is null
4

1 回答 1

2

用这个:

environment {
    NEW_VAR = "${env.SOME_VAR}"
}

这样你就可以进行字符串插值,然后将字符串值分配给新的 var。
刚刚测试过,应该可以的。

于 2017-08-14T14:31:34.663 回答