gpt4 book ai didi

jenkins - 从 Jenkins 管道并行步骤收集数据

转载 作者:行者123 更新时间:2023-12-02 17:55:59 26 4
gpt4 key购买 nike

从并行步骤收集数据(例如通过/失败结果)的最佳方式是什么。

到目前为止我所达到的目标:

#!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)
}
}

但是失败了:

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)

  1. 看起来闭包中它成功填充了 map ,但是在使用函数时它会抛出错误
  2. 我不确定拥有全局 map 是最好/最干净的方式

任何建议

最佳答案

使用.asSynchronized() :

targets = ["a", "b"]

tasks = [:]
spam = [:].asSynchronized()

targets.each { target ->
tasks[target] = {
echo "dry-run ${target}"
spam[target] = "BEEN THERE"
fspam(target, spam) // <--- passing spam fixes the issue
}
}

parallel tasks

print("spam")
print(spam)

这保证了 map 的更新是线程安全的。要收集列表,您可以使用[].asSynchronized()Link

关于jenkins - 从 Jenkins 管道并行步骤收集数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54867601/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com