【问题标题】:Distributed build in JenkinsJenkins 中的分布式构建
【发布时间】:2020-02-27 06:33:18
【问题描述】:

我在 Jenkins 有一项测试执行工作。该作业包含许多测试用例,因此为了减少构建时间,我希望它以分布式方式执行。假设作业有 100 个测试用例,如果我触发作业构建,那么从属 1 应该执行 50 个测试用例,从属 2 应该执行剩余的 50 个测试用例。如何实现这个场景?

提前致谢。

【问题讨论】:

    标签: jenkins


    【解决方案1】:

    使用Jenkins Pipeline,您可以在parallel 部分的帮助下轻松地在任意数量的代理之间分配工作任务。示例Jenkinsfile 做你想做的事情可能看起来像这样:

    pipeline {
        agent none 
        stages {
            stage('Tests') {
                parallel {
                    stage('Tests1') {
                        agent { label 'slave1' }
                        steps {
                            echo "tests part 1"
                        }
                    }
                    stage('Tests2') {
                        agent { label 'slave2' }
                        steps {
                            echo "tests part 2"
                        }
                    }
                }
            }
        }
    }
    

    对于更复杂的场景,您可以添加 matrix 部分并结合标记代理。

    假设您有一些标记为 'test-runner' 的 Jenkins 从属服务器,并且您将测试分成 10 个部分。使用matrix,您一次最多可以运行 10 个任务(受代理数量限制):

    pipeline {
        agent none
        stages {
            stage('Distribute Tests') {
                matrix {
                    axes {
                        axis {
                            name 'PART'
                            values '1', '2', '3', '4', '5', '6', '7', '8', '9', '10'
                        }
                    }
                    stages {
                        stage('Tests') {
                            agent { label 'test-runner' }
                            steps {
                                echo "tests part ${PART}"
                            }
                        }
                    }
                }
            }
        }
    }
    

    【讨论】:

    • 非常感谢@Tupteq 的快速回复
    猜你喜欢
    • 2014-12-13
    • 1970-01-01
    • 2012-06-09
    • 2023-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-16
    • 2015-04-01
    相关资源
    最近更新 更多