How to run a shell script on remote machine through ssh using jenkins job How to run a shell script on remote machine through ssh using jenkins job shell shell

How to run a shell script on remote machine through ssh using jenkins job


I suggest you to follow the following steps:

  1. Configure your remote machine as slave node.
    • Jenkins provide Node properties
    • go to Node Properties > Environmental Variables > there you can give the name and value for configuration. I have followings in my setup:

name: remotemachine1value: 172.20.16.120

name:USERNAMEvalue: user

  1. After you are done with Jenkins Node configuration, you can create a Jenkins Job and configure the Jenkins job.Jenkins configuration Build step provides "Execute Windows batch command" and you can run your shell script there. Please do not forget to specify your remote machine in "Restrict where this project can be run" step inside Jenkins job configuration.

Please let me know if you have any specific further questions.


Stumbled upon an similar problem right now and you could try to solve it this way:

for HOSTNAME in ${HOSTS} ; do     sshpass -p password ssh -t -t ${USERNAME}@${HOSTNAME} '(        pwd        ls -l        <put your script here>    )'done