我知道我可以有一个关于 jenkins 管道(声明性)的环境部分。像这样:
stage('Name') {
environment {
NAME = value
}
steps {
script {
Do something using these env vars
}
}
}
Run Code Online (Sandbox Code Playgroud)
我想编写一个 groovy 函数,定义一些环境变量,运行一些东西,并从几个管道中调用它。就像是:
def function () {
environment {
NAME = value
}
sh "do something using these env vars"
}
Run Code Online (Sandbox Code Playgroud)
有可能吗?
(我知道我可以写,sh "ENV=value; some CMD"但我的变量很少,而且可读性较差)。