詹金斯Groovy并行变量不起作用 [英] Jenkins Groovy Parallel Variable not working

查看:126
本文介绍了詹金斯Groovy并行变量不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下脚本运行Jenkins Build Flow Plugin:

I'm running the Jenkins Build Flow Plugin with the following script:

def builds = [:]

[1,2].each { 
  builds[it] = { build("test", parm: ("$it"))  }
}

parallel builds 

然而,尽管散列(build [it])被正确填充,始终为空。我也尝试了以下方法:

However, whilst the hash (builds[it]) gets populated correctly, the parm is always null. I've also tried the following:

builds[it] = { build("test", parm: $it))  }
builds[it] = { build("test", parm: it))  }



<但它总是空。

But the it is always null.

任何人都可以给我任何指示,告诉我如何使用$ it或任何其他变量在构建作业中。

Can anyone give me any pointers as to how I can use the $it, or any other variable in the build jobs please.

推荐答案

似乎您遇到了Build Flow插件中的一个错误(我见过与Pipeline DSL类似的问题)。没有专家,但它似乎与Groovy关闭和由每个 foreach 提供的外部变量的范围有关。结构体。
例如(与您的示例类似):

Seems like you are running into a bug in Build Flow Plugin (I've seen similar issues with Pipeline DSL). No expert, but it seems to be related to groovy closures and scoping of outer variables that are provided by each or foreach constructs. For example (smilar to your example):

def builds = [:]

[1,2].each { 
  builds[a] = { print "${it}\n"  }
}

parallel builds

打印:

prints:

null
null

while:

while:

def builds = [:]

[1,2].each { 
  def a = it;
  builds[a] = { print "${a}\n"  }
}

parallel builds 

会打印

1
2

。因此,请使用局部变量来存储迭代值。

as expected. So, use an local variable to store the iteration value.

这篇关于詹金斯Groovy并行变量不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆