How to Trigger builds remotely in Jenkins?
1. Create a user – You need to create a user in jenkins using you would like to trigger a jenkins jobs from remote loction or script
How to create users in Jenkins?
Manage Jenkins –> Manage Users –> Create User
2. Assign a right privillage to the specific user?
How to assign privillage to the user?
Manage Jenkins –> Configure Global Security –> Enabled “Anyone can do anything”
Manage Jenkins –> Configure Global Security –> Configure “Matrix-based security” for the specific users and assign atleast following Permissions.
Overall – Read
Job – Build
Job – Read
Job – Workspace
3. Find out jenkins user “API Token”
How to find jenkins user “API Token”?
Click on the user name located at top right(e.g http://184.108.40.206:8080/user/admin1/) –> Configure –> Locate the “API Token” section.
4. Enabled “Trigger builds remotely” in Jenkins Job Configuration.
Click on the desired job –> Configure –> Locate the “Trigger builds remotely” under “Build Triggers” Tab
Enabled the check box of “Trigger builds remotely”
Provide some Authentication Token e.g – iFBDOBhNhaxL4T9ass93HRXun2JF161Z
5. Formulate the command to run using curl.
> curl –user userid:API-Token http://IP OR HOST:PORT/job/JOB_NAME/build?token=Authentication_Token
eg.curl –user admin1:91367cf0389eaf89669f74c9963c9fb3 http://220.127.116.11:8080/job/ANT-BUILD/build?token=iFBDOBhNhaxL4T9ass93HRXun2JF161Z
Some of other formats which is being tried in google but need to be tested with specific users. there are working with “Anonymous”
> curl -X POST http://admin1:firstname.lastname@example.org:8080/job/ANT-BUILD/build?token=iFBDOBhNhaxL4T9ass93HRXun2JF161Z
If you are using wget 1.11 against Jenkins version 1.586 and above with the JENKINS-25169 fix, you might need to use the following options:
wget –auth-no-challenge –http-user=user –http-password=apiToken –secure-protocol=TLSv1 http://jenkins.yourcompany.com/job/your_job/build?token=TOKEN
If you are using wget 1.11, you might need to use the following options:
wget –auth-no-challenge –http-user=user –http-password=apiToken http://jenkins.yourcompany.com/job/your_job/build?token=TOKEN
With wget 1.10.x the following is enough (but will not work with 1.11.x) :
If you are a Windows User!
‘gitbash’ is a program combined of git and bash. A bash is shell that runs commands once you type the name of command and press enter. 🙂