使用Jenkins并行运行任务

5

我有几百个文件需要进行测试(每个测试需要几分钟)。

顺序运行和全部一起运行都不可接受。因此,我正在寻找类似于生产者-消费者的东西。

我尝试了使用管道作业和以下方式的并行命令:

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

问题:

所有任务同时启动(OOM和所有有趣的事情)


解决方案:

所有任务同时启动可能导致内存不足和其他问题。

1个回答

0

虽然它似乎不支持固定池,但与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 "{}"'

-P 参数用于指定始终运行固定数量的 2 (或 N) 个进程。其他工具(如 GNU Parallel)可以提供更多有关使用多少进程的优化。

你也可以尝试从 Lockable Resources 插件 中使用 lock 步骤,或者使用 node 步骤来针对固定数量的执行器。然而,除非你的单个测试已经每个都花费了数十秒,否则这似乎是太浪费效率了。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接