Jenkins: Publish Over SSH to multiple hosts without copy/paste

Jenkinsjmeter

I'm using Jenkins' Publish Over SSH Plugin to transfer the same set of files to a group of hosts and then run a small script there. Using the "add server" feature however requires me to repeat source files, remote directory and exec command for every additional server.

https://wiki.jenkins.io/display/JENKINS/Publish+Over+SSH+Plugin

What I'm looking for is a way to specify a list of ssh servers for which the plugin should be executed, preferably in parallel, though the number of servers (4-12) is small enough for a sequential flow too.

Some project specific context:

  • The publish task is to transfer a JMeter server to a number of load generators and start it there
  • It is part of the "Build Environment" section right now because the actual build is the execution of the JMeter scenario. If it makes more sense to move any of these steps to a different section, I'm open to that.

Thanks in advance for suggestions.

Best Answer

You can also configure an "Execute shell" block and run there something like:

#!/bin/bash
LISTFILE="servers.list"
for server in $(cat $LISTFILE); do 
  pssh -i -p $SESSIONS -O ConnectTimeout=$TIMEOUT -h $LISTFILE "$COMMANDS"
done

pssh is a free parallel ssh client, more information can be found here.