Have Jenkins Run A Shell Script In A Remote Machine Every Time There Is A Change In The Git Repository
By Diwanshu Shekhar
- 2 minutes read - 356 wordsFrom Jenkins home page, click on “New Item” and select a “Freestyle Project” and fill in the general details such as “Project Name and Description”
Under the Source Code Management tab, add your code repository URL and set up the ssh credential so that Jenkins will be able to poll after certain intervals.
You will need to generate a pair of public and private RSA key and put the public key in your repository and the private key in your Jenkins Source Code Management section by clicking on the “add” button which opens up a new window as shown below where you add in the ssh credential.
Then, we set up the Build Trigger section where we have Jenkins poll the repository we added in the earlier step. As shown in the figure, I am having it poll every 15 minutes.
Next thing we want to do is to step the Build Environment. In this step, we can set things that we want to do before and after the actual build step. I decided to run my test script before the build and the screenshot below shows the set up. As you can see, you need to select the ssh server which is the remote machine where you want your script to run. To set up the ssh server, you need to go to the home page of Jenkins and select “Manage Jenkins” and select “Configure Jenkins” and set up your ssh server.
When you come back to this section after you set up your ssh server, you will see the name of your ssh server in the pull-down list. Here you can set up the ssh credential as password or key. I have set it as a password.
Since we are only running a shell script, there is nothing to build and that is the reason why we leave the Build Section empty empty.
The last step Post-Build Section is optional but you can use it to set up your email notification. But that’s it. Following the above steps will run your bash script every time there is a new code in your code repository.