有没有办法,我可以访问闭包外的变量。这里的闭包是 Jenkinsfile
中的一个 stage
。因此,代码段如下所示:
node('pool'){
try{
stage('init'){
def list = []
//some code to create the list
}
stage('deploy'){
//use the list create in the above stage/closure
}
}
catch(err){
//some mail step
}
}
使用此代码,我无法访问在第一个 stage/closure
中创建的 list
。
我如何设置才能让这个新创建的 list
可用于下一阶段/关闭?
最佳答案
@tim_yates.. 听取您的建议。这行得通。最后很容易:)
node('pool') {
try {
def list = [] //define the list outside of the closure
stage('init') {
//some code to create/push elements in the list
}
stage('deploy') {
//use the list create in the above stage/closure
}
} catch (err) {
//some mail step
}
}
关于groovy - 在 Groovy 中访问闭包之外的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42635047/