tra*_*rax 5 jenkins jenkins-pipeline
我有几个(几百个)文件要运行测试(每个测试需要几分钟).
顺序运行是不可接受的,也不是全部.所以我正在寻找像生产者 - 消费者这样的东西.
我通过以下方式尝试了管道作业和并行命令:
def files = findFiles glob: 'test_files/*'
def branches = [:]
files.each{
def test_command = "./test ${it}"
branches["${it}"] = { sh "${test_command} ${it}"}
}
stage name:'run', concurrency:2
parallel branches
Run Code Online (Sandbox Code Playgroud)
问题:
所有任务都在同一时间启动(OOM和所有的乐趣)
没有与 Jenkins 并行步骤相同的自省,但由于它似乎不支持固定池,您可以使用它xargs来实现相同的结果:
def files = findFiles glob: 'test_files/*'
def branches = [:]
// there's probably a more efficient way to generate the list of commands
files.each{
sh "echo './test ${it}' >> tests.txt"
}
sh 'cat tests.txt | xargs -L 1 -I {} -P 2 bash -c "{}"'
Run Code Online (Sandbox Code Playgroud)
该-P参数指定应始终运行固定数量的 2 个(或 N 个)进程。其他工具(例如 GNU Parallel)对应使用的进程数量提供了更多调整。
您还可以尝试使用Lockable Resources 插件lock中的步骤,该步骤针对固定数量的执行器。然而,这对我来说似乎太大了,除非你的单个测试已经每次花费数十秒。node
| 归档时间: |
|
| 查看次数: |
330 次 |
| 最近记录: |