jenkins - 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
与标记代理相结合的部分。
假设您标记了一些 Jenkins slave 'test-runner'
,并且您将测试分成 10 个部分。一次最多可以运行 10 个任务(matrix
受代理数量限制):
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}"
}
}
}
}
}
}
}
推荐阅读
- r - 使用 dplyr 在 R 中插入新行而不指定列名
- spring-boot - 连接 react-native、springboot
- javascript - IDBIndex.getAll() 是否返回排序列表?
- c# - 在 C# 中分配没有多个 for 循环的 StackElements
- java - Mapstruct 忽略 @BeanMappingqualifiedByName
- intellij-idea - 用于嵌套构建器的 Intellij Idea 代码标识
- c# - 我可以让我的代码不接受除 int C# 之外的任何输入吗
- single-page-application - 仅针对静态内容的 Web 服务器瓶颈
- c# - 如何将第一行保持在顶部,并且只滚动网格中第二行的内容
- google-chrome - 如何在 Windows 10 中禁用 Chrome 菜单右上角的无法更新 Chrome 警告?