如何访问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
答案 0 :(得分:2)
使用此:
environment {
NEW_VAR = "${env.SOME_VAR}"
}
通过这种方式,您正在执行string interpolation,然后将字符串值分配给新的var 刚刚测试过,这应该可行。