04/06/2017 - JENKINS
This example shows us how to trigger jenkins job/build via curl command in terminal. Step by step we will be building curl command below in order to trigger jenkins jobs from command line.
$ curl -X POST http://API_USER_ID:API_TOKEN@JENKINS_URL/job/JOB_NAME/build -H "CRUMB"
The name of my job is
Football. I would also suggest you to create a dedicated jenkins user and password rather than using
admin:admin as I'll use in this example. My jenkins GUI URL is
http://192.168.99.20:8080 as I am on vagrant.
Use the following URL to trigger build remotely: JENKINS_URL/job/Football/build?token=TOKEN_NAME or /buildWithParameters?token=TOKEN_NAME. Optionally append &cause=Cause+Text to provide text that will be included in the recorded build cause..
admin) on right hand side of the page.
For more information, visit Remote access API page.
$ wget -q --auth-no-challenge --user admin --password admin --output-document - 'http://192.168.99.20:8080/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)'
This will give you something like
Jenkins-Crumb:44e7033af70da95a47403c3bed5c10f8. Without crumb information, running curl command will result in example errors such as
HTTP/1.1 403 Forbidden or
Error 403 No valid crumb was included in the request.
$ curl -I -X POST http://admin:firstname.lastname@example.org:8080/job/Football/build -H "Jenkins-Crumb:44e7033af70da95a47403c3bed5c10f8"
HTTP/1.1 201 Created
Date: Fri, 02 Jun 2017 06:17:51 GMT
Note: You can remove
-I flag if you don't want output.