从Jenkins管道并行步骤收集数据 [英] collect data from Jenkins pipeline parallel steps
问题描述
从并行步骤收集数据(例如通过/失败结果)的最佳方法是什么.
What would be the best way to collect data (such as pass/fail results) from parallel steps.
到目前为止我已经达到的目标:
What I've reached so far:
#!groovy
def fspam(name, spam){
spam[name] = "BEEN THERE TOO"
}
// pipeline
node('slave'){
stage("test"){
targets = ["a", "b"]
def tasks = [:]
def spam = [:]
targets.each{ tasks["${it}"] = {
node('slave'){
echo "dry-run ${it}"
spam[it] = "BEEN THERE" <--- works
fspam(it) <--- fails
}
}
}
parallel tasks
print("spam")
print(spam)
}
}
但是失败了:
也:groovy.lang.MissingPropertyException:无此类属性:stam 适用于类:WorkflowScript groovy.lang.MissingPropertyException:否 此类属性:stam类:WorkflowScript,位于 org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53)
Also: groovy.lang.MissingPropertyException: No such property: stam for class: WorkflowScript groovy.lang.MissingPropertyException: No such property: stam for class: WorkflowScript at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53)
- 似乎封闭式地成功填充了地图,但是使用函数时会引发错误
- 我不确定拥有全球地图是最好/最干净的方式
任何建议
推荐答案
使用
这保证了对映射的更新是线程安全的.要收集列表,可以使用 This guarantees that updates to the map are thread-safe. For collecting a list, you can use 这篇关于从Jenkins管道并行步骤收集数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋![].asSynchronized()
. 链接 [].asSynchronized()
. Link