- Get the config.xml from a pre-created job or create another one according to the need :
➜ curl -X GET http://localhost:8080/job/test-pipeline/config.xml -u admin:admin -o config.xml
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1599 100 1599 0 0 18518 0 --:--:-- --:--:-- --:--:-- 18593
➜ CRUMB=$(curl -s 'http://localhost:8080/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)' -u admin:admin)
➜ echo $CRUMB
Jenkins-Crumb:d11aea06df13cdeb17ab7a12f2832eae
- Use xml to create another jenkins job :
➜ curl -s -XPOST 'http://localhost:8080/createItem?name=api-job-test' -u admin:admin --data-binary @config.xml -H "$CRUMB" -H "Content-Type:text/xml"
https://support.cloudbees.com/hc/en-us/articles/220857567-How-to-create-a-job-using-the-REST-API-and-cURL-