Jenkins Pipeline-在多个远程主机上并行运行作业 [英] Jenkins Pipeline - Run job on parallel on multiple remote hosts
问题描述
我有一个Jenkins作业,其字符串参数为Name ="HOST".我试图通过连接到主机来远程运行一个脚本.它工作正常.同样,如果我在HOST参数中输入多个主机名,则该作业必须在这些多台计算机上并行运行.如何实现呢?
I have a Jenkins job with string parameter Name = "HOST". I am trying to run one script remotely by connecting to the HOST. It works fine. Similarly, if I enter multiple host names in the HOST parameter, the job has to run on those multiple machines on parallel. How to achieve this?
如果有人对此有任何代码,请分享.感谢您的帮助!
If anybody has any code for this, please do share. Appreciate this help!
推荐答案
An easy way to run a job on different machines in parallel is to use the declarative Matrix.
管道示例:
pipeline {
agent none
stages {
stage('Matrix stage') {
matrix {
agent {
label "${NODE}"
}
axes {
axis {
name 'NODE'
values 'node1', 'node2', 'node3'
}
}
stages {
stage('Parallel stage') {
steps {
echo "Run on ${NODE}"
}
}
}
}
}
}
}
此pipleline将在['node1','node2','node3']上并行执行已定义的阶段.
This pipleline will execute the defined stages on ['node1', 'node2', 'node3'] in parallel.
请注意,声明性Matrix是本机声明性管道功能,因此不需要额外的插件安装.
Note that declarative Matrix is a native declarative Pipelines feature, so no additional Plugin installation needed.
这篇关于Jenkins Pipeline-在多个远程主机上并行运行作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!