DDK
DDK

Reputation: 1038

How to execute command line script on a different machine from Jenkins

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?

Upvotes: 2

Views: 4657

Answers (2)

gaige
gaige

Reputation: 17481

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>"

Upvotes: 1

Lars Kotthoff
Lars Kotthoff

Reputation: 109242

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.

Upvotes: 2

Related Questions