Jenkins task for remote hosts

0 votes

I am working on the deployment scenario in which I need to create and run jenkins task on list of hosts, i.e. create something like parametrized task (where ip address is a parameter) or a task on Multijob Plugin with HOST axis, but run by only 2 ones in parallel over multiple hosts. 

One of the option could be to run ansible with the list of hosts, but i'd like to see a status per each host separately, and relaunch a jenkins job if needed.

The main option is to use Job DSL Plugin or Pipeline Plugin, but here i need help to understand what classes/methods of dsl groovy code should be used to achieve this. 
Can anyone help with it?

Jul 24, 2018 in Jenkins by Damon Salvatore
• 5,980 points
1,276 views

1 answer to this question.

0 votes

Here is a concept which you can follow. Assume that the hosts have been configured as Jenkins slaves already. Assume that hosts are provided in pipeline job parameter HOSTS as whitespace separated list.Below is an example which you can take reference from:

def hosts_pairs = HOSTS.split().collate(2)

for (pair in host_pairs) {
  def branches = [:]
  for (h in pair) {
    def host = h  // fresh variable per iteration; it will be mutated
    branches[host] = {
      stage(host) {
        node(host) {
          // do the actual job here, e.g. 
          // execute a shell script
          sh "echo hello world"
        }
      }
    }
  }
  parallel branches
}  


I hope the above information would resolve your query.

answered Jul 24, 2018 by Atul
• 10,240 points

Related Questions In Jenkins

0 votes
1 answer

Why is it displaying Jenkins build failure for Android app

I think you should try this. Try Uninstalling ...READ MORE

answered Apr 12, 2018 in Jenkins by shubham
• 7,340 points
1,505 views
0 votes
2 answers

Is possible for Jenkins to auto start and stop slave nodes?

Try Jenkins Plugin called as Slave SetupPlugin. This ...READ MORE

answered Aug 6, 2018 in Jenkins by Nilesh
• 7,050 points
6,288 views
0 votes
1 answer

Error while communicating with remote Oracle DB through Jenkins-CI

I was also facing the same problem. ...READ MORE

answered Apr 25, 2018 in Jenkins by shubham
• 7,340 points
764 views
0 votes
1 answer

Error while talking to remote Oracle DB using Jenkins-CI

I installed Oracle XE to talk to ...READ MORE

answered May 1, 2018 in Jenkins by shubham
• 7,340 points
1,664 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
3,460 views
+2 votes
1 answer
0 votes
1 answer

sonar XML plugin installation failure in jenkins

You can try this link which SonarQube XML ...READ MORE

answered Jun 21, 2018 in Jenkins by Atul
• 10,240 points
695 views
+2 votes
4 answers
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP