Jenkins Pipeline-在多个远程主机上并行运行作业 [英] Jenkins Pipeline - Run job on parallel on multiple remote hosts

查看:1601
本文介绍了Jenkins Pipeline-在多个远程主机上并行运行作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆