Jenkins中的分布式构建



我在Jenkins中有一个测试执行作业。该工作由许多测试用例组成,因此为了减少构建时间,我希望它以分布式方式执行。假设作业有100个测试用例,如果我触发作业构建,那么从机1应该执行50个测试用例而从机2应该执行剩余的50个测试案例。如何实现这种情况?

提前谢谢。

借助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 slave,并且您将测试分为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}"
}
}
}
}
}
}
}

最新更新