运行 Jenkins 中多个节点上的同一阶段
Run same stage on multiple nodes in Jenkins
我有以下 Jenkinsfile,我想在其中 运行 3 个节点上的舞台。
我根据 .
使用了 && 运算符
pipeline{
agent {
label 'webserver && serverex && composeserver'
}
stages{
stage('run this on 3 nodes'){
steps{
script{
sh 'echo $HOSTNAME'
}
}}
}}
但是我遇到了以下错误。
There are no nodes with the label ‘webserver&&serverex&&composeserver’
以上stage为例,我在同一个stage下有多个脚本
我可以使用并行实现这一点,但它会重复,因为我需要在 3 个节点上 运行 它。
我可以知道 AND (&&) 运算符有什么问题吗?根据 link 中提到的答案,它是否已从 Jenkins 中删除,因为它看起来像以前一样工作?
我认为您误解了那个答案。您只能在 node([...])
中引用单个节点,&&
允许您声明多个标签,jenkins 在 select 找到适当的节点时将查找这些标签。
例如,当代理 A 的标签为 maven windows selenium
和代理 B 的标签为 maven linux docker
时,代理 C 的标签为 maven gcc linux
,node('maven')
将成为 select 节点A、B 或 C 取决于执行者的生存能力,当你在某些 linux-only sh
步骤中混合时,这可能是一个问题,因此你可以使用 node('maven && linux')
让詹金斯选择其中一个后两个代理都包含这些标签。
如果您想 运行 多个节点上的相同内容,您可以遍历节点标签数组。
def labels = ['label1', 'label2']
for (label in labels) {
node(label) {
stage('Running on ' + label){
// Do stuff
}
}
}
我有以下 Jenkinsfile,我想在其中 运行 3 个节点上的舞台。
我根据
pipeline{
agent {
label 'webserver && serverex && composeserver'
}
stages{
stage('run this on 3 nodes'){
steps{
script{
sh 'echo $HOSTNAME'
}
}}
}}
但是我遇到了以下错误。
There are no nodes with the label ‘webserver&&serverex&&composeserver’
以上stage为例,我在同一个stage下有多个脚本
我可以使用并行实现这一点,但它会重复,因为我需要在 3 个节点上 运行 它。
我可以知道 AND (&&) 运算符有什么问题吗?根据 link 中提到的答案,它是否已从 Jenkins 中删除,因为它看起来像以前一样工作?
我认为您误解了那个答案。您只能在 node([...])
中引用单个节点,&&
允许您声明多个标签,jenkins 在 select 找到适当的节点时将查找这些标签。
例如,当代理 A 的标签为 maven windows selenium
和代理 B 的标签为 maven linux docker
时,代理 C 的标签为 maven gcc linux
,node('maven')
将成为 select 节点A、B 或 C 取决于执行者的生存能力,当你在某些 linux-only sh
步骤中混合时,这可能是一个问题,因此你可以使用 node('maven && linux')
让詹金斯选择其中一个后两个代理都包含这些标签。
如果您想 运行 多个节点上的相同内容,您可以遍历节点标签数组。
def labels = ['label1', 'label2']
for (label in labels) {
node(label) {
stage('Running on ' + label){
// Do stuff
}
}
}