First we have to setup your Jenkins server. To do that start your jenkins server & login to your Jenkins from Web Interface, and then setup 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 “Manage Plugins” option -
You will redirect to the ‘Plugin Manager’ page. Click on ‘Installed’ tab and search with ‘Authentication Tokens API Plugin’. Check “Authentication Tokens API Plugin” plugin is installed to your jenkins server or not.
If plugin isn't intalled to your jenkins server then click on 'Available' tab and install it and restart your jenkins server.
Now go to your respective jenkins job configuration page and scroll to “Build Triggers” section. In this section check 'Trigger builds remotely (e.g., from scripts)' option. Enter your Authenication Token if you have otherwise leave it as it is.
Now save your job configuration by clicking on 'Save' button.
Trigger Jenkins Job From Remote System :
Download 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 port number from user.)
Now open command prompt and navigate to your jar file location where you have save it earlier.
Run your jar file by typing following command:
java -jar trigger-jenkins-job.jar
Enter required details asked at runtime i.e username, password, jenkins server_url etc (Make sure repective user should have permission to trigger respective job) and that's it, You can check in your jenkins server respective jenkins job has been triggered.