Take the 2-minute tour ×

I access Jenkins dashborad located on the server called myserver by accessing the url http://<myserver>:8080/. I have written my build steps on the build part of the job configuration page. After completing the build steps, I need to access a different server and execute a command line script. How do I run the command line script on different server from my current node?

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

We have what sounds like a similar situation where we run some automated tests that must be initiated on a non-Jenkins host. For this, we use ssh and keyed authentication, which requires a bit of setup in the Execute shell step:

# generic prep
eval `ssh-agent -s`
ssh-add ~/.ssh/my-agent-key

At this point, the key is now in the ssh-agent keyring and you can ssh without needing to worry about passwords to any account and host that accepts that key.

ssh testuser@targetmachine "<commands>"
share|improve this answer
Thanks for suggesting to use SSH. –  DDK Apr 3 '13 at 6:21
add comment

You have basically two options. The first one is to connect to the machine you want to run the script on in a build step (for example using SSH) and run all the required commands this way. You would need to set up passworldess access (e.g. using SSH keys) for this.

The second option would be to add the second machine as a Jenkins slave, add a second job that is tied to this slave and runs the latter part of the build and tell Jenkins to run this second job when the first job is done. If you need to pass files from the first job to the second, you could make them available as artifacts and download them in the second build.

I would go for the second solution as it's conceptually cleaner. It's more work to set up though.

share|improve this answer
Thanks. I have used ssh for connecting to the second machine where I wanted to run the script. I have restricted access to the second machine, So making it as a slave was not possible. –  DDK Apr 3 '13 at 6:17
add comment

Your Answer


