Jenkins REST API Create job
Solution 1:
Jenkins by default has CSRF Protection enabled which prevents one-click attacks. To invoke the request, you need to obtain the crumb from /crumbIssuer/api/xml
using your credentials and include it into your request.
For example:
CRUMB=$(curl -s 'http://USER:TOKEN@localhost:8080/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)')
Then you can create a job (by including the crumb into your header):
curl -X POST -H "$CRUMB" "http://USER:TOKEN@localhost:8080/createItem?name=NewJob"
If the above won't work, check your crumb (echo $CRUMB
) or run curl
with -u USER:TOKEN
.
For a more detailed explanation, see: Running jenkins jobs via command line.