在不同节点上运行Jenkins阶段 [英] Run Jenkins stage on different nodes
问题描述
我具有以下多分支管道体系结构的Jenkinsfile
I have the following Jenkinsfile of a multibranch pipeline architecture
#!/usr/bin/groovy
pipeline {
agent {
node {
label 'ubuntu'
customWorkspace "/src/$BUILD_NUMBER"
}
}
environment {
SRC_DIR = "$WORKSPACE"
BUILD_DIR="/build/$BUILD_NUMBER"
}
stages {
stage('Build') {
steps {
dir(BUILD_DIR) {
sh '$SRC_DIR/build.sh'
}
}
}
stage('Test') {
steps {
dir(BUILD_DIR) {
sh '$SRC_DIR/test.sh'
}
}
}
}
}
我试图在Ubuntu和Red Hat节点上并行运行"Build"阶段,并且仅在Ubuntu节点上运行"Test"阶段.
I am trying to run the 'Build' stage on Ubuntu and Red Hat nodes in parallel, and the 'Test' stage on the Ubuntu node only.
有人可以帮助我指定如何选择在哪些节点上运行哪个阶段.我在网上找不到很少的解决方案,但他们建议重写构建阶段两次:一次用于Red Hat节点,另一个用于Ubuntu节点.没有代码重复,没有办法做到这一点吗?
Can anybody help me in specifying how to choose which stage are run on which nodes. I found few solutions online but they recommended rewriting the build stage twice: once for the Red Hat node and the other for the Ubuntu node. Isn't there a way to do this without code duplication ?
非常感谢
推荐答案
当然,您希望以某种方式标记您的从属节点.基本上在Jenkins上配置所有节点,并为其赋予有意义的名称.
Sure, you would want to label your slave nodes somehow. Basically configure all the node on Jenkins and give them meaningful names.
stage('Build') {
steps {
node('os_linux') {
sh './build.sh'
}
node('os_redhat') {
sh './build.sh'
}
}
这将以串行方式运行任务,并且Jenkinsfile语法还支持在不同节点上并行执行命令.
This will run the tasks in serial, and Jenkinsfile syntax also supports executing commands in parallel on different nodes.
谢谢
这篇关于在不同节点上运行Jenkins阶段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!