jenkins - 如何在jenkins groovy中并行运行方法
问题描述
我有 jenkins 共享库,其中包含内部方法(我们称之为 A())
目前 A() 方法按顺序运行 10-100 次。
我想与预定义的批量编号 (10) 并行运行 A()
我没有找到通过 groovy 实现它的方法,Jenkins 的一些方法需要批准。
在不需要任何詹金斯批准的情况下,通过 groovy (不是詹金斯的并行步骤)来做到这一点的方法是什么?
解决方案
我不知道您是否需要此权限,但请尝试一下:
def A = {
println "hello from A($it)"
Thread.sleep(Math.random() * 2000 as long)
println "hello from A($it)"
}
def threads = (0..5).collect { counter ->
Thread.start { A(counter) }
}
threads.each { it.join() }
我放了println
一些睡眠来演示并行运行的方法。您可以根据需要更换身体A{}
。
推荐阅读
- flask - 具有多个路由参数的 Swagger UI 问题
- geometry - 如何获得偏移量,以便我的立方体齐齐齐平?
- excel - 如何在 Excel 中将“2016 年 12 月 9 日”形式的日期拆分为三个单独的列“12”“09”“2016”?
- javascript - 如何使用 JS 计算 div 而不是整个页面的滚动百分比?
- java - 订阅 Firebase 主题不会过滤消息
- python - 如何将 np,load() 与张量一起使用?
- r - reticulate python engine - 使用 r 作为多个块之间共享的 Python 对象的名称
- c++ - 如果读取处理程序不会被调用,有什么方法可以知道在 async_read 函数中传输的字节数?
- litespeed - 在 OpenLiteSpeed 上允许/拒绝 IP
- bash - 在 bash 编程中找不到 pg_dump 命令