multithreading - 在 Groovy 中同时运行 FOR LOOP?
问题描述
我正在尝试找到可以在 Groovy 中同时运行 FOR 循环的选项?我有一个 Jenkins 文件,我希望 for 循环在那里并行运行
类似于以下代码。我希望所有这些 for 循环都可以并行运行。订单不是问题。只是for循环里面的步骤应该已经完成了。
vars=[*,*,*,*,*]
for i in vars:
'''steps'''
解决方案
您需要使用并行指令。这就是你可以为 for 循环做的事情。您应该能够使用此代码并使其适应您的
def testList = ["a", "b", "c", "d"]
def branches = [:]
for (int i = 0; i < 4 ; i++) {
int index=i, branch = i+1
branches["branch_${branch}"] = {
sh "echo 'node: ${NODE_NAME}, index: ${index}, i: ${i}, testListVal: " + testList[index] + "'"
}
}
parallel branches
推荐阅读
- reactjs - 无法获取直接 url 以使用 react 路由器 dom
- python - 删除列表的元组以仅生成一个元组 Python
- ruby-on-rails - Ruby on Rails 将动态 URL 重定向到静态 URL
- c# - 如何使用 Swashbuckle 从 C# 中的 URL 读取 OpenAPI JSON 文件?
- javascript - 使用 connectOrCreate 时 prisma 出错
- python - 尝试使用 Lambda 函数并获取 NAN
- mysql - 弧度函数内的 Mysql 查询不起作用。为什么?
- python - Python3.6: pool.map throws -- AssertionError: daemonic processes are not allowed to have children
- javascript - 如何访问使用 supertiler 库创建的群集矢量源的 clusterProperties?
- ansible - Ansible:使用 yaml 库存的两个主机组的交集