简体   繁体   English

如何使用单个作业配置在多个从站上运行Jenkins作业?

[英]How to run Jenkins jobs on multiple slaves with a single job configuration?

I have three different environments each containing a Jenkins Slave, 我有三个不同的环境,每个环境都包含一个詹金斯奴隶,

STAGE1 - slave1 STAGE1 - slave1
STAGE2 - slave2 STAGE2 - slave2
STAGE3 - slave3 STAGE3 - slave3

I don't want to create three different build jobs for them. 我不想为他们创建三个不同的构建作业。

I want to pass the slaves ( slave1 , slave2 and slave3 ) as parameters, so that if I choose slave1 the job gets executed on STAGE1 , and if I choose slave2 the job gets executed on STAGE2 and so on. 我希望将slave( slave1slave2slave3 )作为参数传递,这样如果我选择slave1 ,则在STAGE1上执行作业,如果我选择slave2则在STAGE2上执行作业,依此类推。

How to achieve that using a single Jenkins job? 如何使用单个Jenkins工作实现这一目标?

I know there is multi configuration job but I am not clear on how to configure it. 我知道有多配置工作,但我不清楚如何配置它。

It would be really helpful if I get some information on it. 如果我得到一些信息,那将非常有用。

I figured it out. 我想到了。 It can be achieved using, 它可以用来实现,

Node and Label Parameter Plugin 节点和标签参数插件

It lets you create node and label parameter in the job configuration. 它允许您在作业配置中创建节点和标签参数。

Node parameter contains all the nodes present in your Jenkins including master, you can select the nodes you want. Node参数包含Jenkins中存在的所有节点,包括master,您可以选择所需的节点。

When you run the job with parameters you can select the desired node and the job will get executed in that particular node. 使用参数运行作业时,可以选择所需的节点,作业将在该特定节点中执行。

I am working in test automation where I need to maintain different environment and deploy jobs to Jenkins, I'm not sure it would be helpful, if it is I will share code snippet(If required). 我在测试自动化中工作,我需要维护不同的环境并将工作部署到Jenkins,我不确定它会有用,如果是的话,我将共享代码片段(如果需要)。

I am not doing exact thing for environment but I've achieved this thing fro browsers, I am using maven as my build tool so I've made configuration in my code that it will fetch the same browser I'm passing in the command which is set as a goal for single Jenkins job. 我没有为环境做一些事情,但我已经从浏览器中实现了这一点,我使用maven作为我的构建工具,所以我在我的代码中进行了配置,它将获取我在命令中传递的相同浏览器被设置为单个Jenkins工作的目标。

Goal example: mvn clean verify -Dtest=test.xml -Dbrowser=chrome

Same can be done for multiple environments as well, you can set a default slave in POM file and make changes configurations changes or you can create 3 multiple files like XML which will contain your executable files and add them as parameter in Jenkins single job. 对于多个环境也可以这样做,您可以在POM文件中设置默认从站并更改配置更改,或者您可以创建3个包含可执行文件的XML等多个文件,并将它们作为参数添加到Jenkins单个作业中。

Hi I was able to achieve to trigger same job in the multiple servers(nodes/slaves) simultaneously with the help of below configuration. 嗨我能够通过以下配置同时在多个服务器(节点/从站)中实现相同的作业。

First you have to create the project as below shown below in the screeshot 首先,您必须在screeshot中创建如下所示的项目

enter image description here 在此输入图像描述

Then configure the details as below 然后配置详细信息如下

enter image description here 在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM