export JENKINS_URL=
export COOKIES=
- Get the config.xml from a pre-created job or create another one according to the need :
curl -X GET "$JENKINS_URL/job/test-pipeline/config.xml" -u admin:admin -o config.xml
CRUMB=$(curl -s "$JENKINS_URL/crumbIssuer/api/json" --cookie "$COOKIES" | python3 -c "import sys, json;i=json.load(sys.stdin);print(i['crumbRequestField']+':'+i['crumb'])")
echo $CRUMB # display value
#output: Jenkins-Crumb:d11aea06df13cdeb17ab7a12f2832eae
- Use xml to create another jenkins job :
curl -X POST "$JENKINS_URL/createItem?name=$jobName" --cookie "$COOKIES" --data-binary @config.xml -H "$CRUMB" -H "Content-Type:text/xml"
- Or, use xml to update exists jenkins job :
curl -X POST "$JENKINS_URL/$jobName" --cookie "$COOKIES" --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-