Jenkins REST API Create job

前端 未结 2 1423
清歌不尽
清歌不尽 2020-11-27 15:51

I\'m creating a new job in Jenkins using the REST API. I tried the below curl command lines, but they are throwing an error

curl -i -X POST --user \"admin:&l         


        
相关标签:
2条回答
  • 2020-11-27 16:17

    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.

    0 讨论(0)
  • 2020-11-27 16:25

    If you are using Postman to fire the requests, using @kenorb example above, get the crumb

    To create a folder at root level using the createItem endpoint

    To create a sub-folder inside the folder created above using the createItem endpoint

    0 讨论(0)
提交回复
热议问题