Skip to content

Instantly share code, notes, and snippets.

@vishnuhd
Created September 3, 2019 11:15
Show Gist options
  • Save vishnuhd/bb87dbfcd15f24b12977a4bf9501a44f to your computer and use it in GitHub Desktop.
Save vishnuhd/bb87dbfcd15f24b12977a4bf9501a44f to your computer and use it in GitHub Desktop.
Create Jenkins pipeline using REST api and CURL
  • 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
  • Generate Crumb :
➜  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"
  • Reference :

https://support.cloudbees.com/hc/en-us/articles/220857567-How-to-create-a-job-using-the-REST-API-and-cURL-

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment