How not knowing Jenkins trigger builds remotely makes you a Rookie!
How Jenkins trigger builds remotely
- Firstly, we have to setup your Jenkins server, so jenkins trigger builds remotely. To do that start your Jenkins server & login from Web Interface. Then, set up your Jenkins Global Tool Configuration.
Click on Jenkins (under header) > Manage Jenkins .
- Now go to Manage Jenkins Page and click on “Configure Global Security.” Here uncheck “Prevent Cross Site Request Forgery exploits” option (If you have crumb issuer then no need to uncheck it) and click on “Save” button.
- Now again from Manage Jenkins page click on the “Manage Plugins” option –
It will redirect to the ‘Plugin Manager’ page. Click on the ‘Installed’ tab and search with ‘Authentication Tokens API Plugin.’ Check if the “Authentication Tokens API Plugin” plugin is installed to your Jenkins server.
If the plugin isn’t installed to your Jenkins server, then click on the ‘Available’ tab and install it. Restart your Jenkins server.
4. Now go to your respective Jenkins job configuration page so that jenkins trigger builds remotely and scroll to the “Build Triggers” section. In this section check ‘Trigger builds remotely (e.g., from scripts)’ option. Enter your Authentication Token if you have else leave it as it is.
Now save your job configuration by clicking on the ‘Save’ button. Jenkins benefits are plenty and it is important to use in the right strategy to enjoy mileage.
Trigger Jenkins Job From Remote System :
- Leave your Jenkins server running and switch to another system. Make sure both the systems are in the same network. Check if you can access Jenkins server from remote machine by entering Jenkins server URL with a port number. In our case, we have Jenkins server running at URL – http://192.168.0.4:8080
- Download the bellow jar file and save it in your system. (currently, in this jar Jenkins server is fixed at 8080 port number, we will enhance our jar and put flexibility to enter the port number from the user.)
Please contact us to download JAR files. - Now open the command prompt and navigate to your jar file location where you have saved it earlier. Run your jar file by typing following command:
java -jar trigger-jenkins-job.jar
- Enter required details asked at runtime- Username, Password, Jenkins server_url, etc. (Make sure the respective user should have permission to trigger the respective job)
And that’s it, You can check in your Jenkins server, respective Jenkins job has been triggered.