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"
OR
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://54.171.140.1: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
$ Save
 
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://54.171.140.1: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:This email address is being protected from spambots. You need JavaScript enabled to view it..1:8080/job/ANT-BUILD/build?token=iFBDOBhNhaxL4T9ass93HRXun2JF161Z
 
> wget http://admin1:This email address is being protected from spambots. You need JavaScript enabled to view it..1:8080/job/ANT-BUILD/build?token=iFBDOBhNhaxL4T9ass93HRXun2JF161Z

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. :)
 
Download  the git bash from here https://git-scm.com/download/win and install it.
 
 

What corporate management say about us?

Trainer & the training material were excellent.

Rohit
Infrastructure Admin, India
Sep 02, 2016

Authors

Login