简体   繁体   English

Jenkins Groovy并行变量不起作用

[英]Jenkins Groovy Parallel Variable not working

I'm running the Jenkins Build Flow Plugin with the following script: 我正在使用以下脚本运行Jenkins Build Flow插件:

def builds = [:]

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

parallel builds 

However, whilst the hash (builds[it]) gets populated correctly, the parm is always null. 但是,尽管正确填充了哈希(builds [it]),但parm始终为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. 但是,它始终为空。

Can anyone give me any pointers as to how I can use the $it, or any other variable in the build jobs please. 任何人都可以给我关于如何使用$ it或构建作业中任何其他变量的任何指示。

Seems like you are running into a bug in Build Flow Plugin (I've seen similar issues with Pipeline DSL). 似乎您在Build Flow Plugin中遇到了一个错误(我已经看到了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. 没有专家,但似乎与eachforeach构造提供的常规闭包和外部变量的作用域有关。 For example (smilar to your example): 例如(与您的示例类似):

def builds = [:]

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

parallel builds

prints: 印刷品:

null
null

while: 而:

def builds = [:]

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

parallel builds 

will print 将打印

1
2

as expected. 如预期的那样。 So, use an local variable to store the iteration value. 因此,请使用局部变量存储迭代值。

As per the build flow documentation I believe the syntax should be: 根据构建流程文档,我认为语法应为:

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

ie the param1 argument name needs to literally read param followed by a sequential integer starting with 1. param1参数名称需要从字面上读取param后跟一个以1开头的连续整数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM