curljenkinsjettyhttp-postjenkins-api

How to POST with Curl to configSubmit Jenkins page


I can do it with Python but not with Curl...

$ curl -H "Content-Type: application/json; charset=UTF-8" --data-urlencode   \
   '{ "description": "This is a test job.", "displayName": "#30: Success" }' \
   -n http://localhost/job/playground/30/configSubmit


<body><h2>HTTP ERROR 400</h2>
<p>Problem accessing /job/playground/30/configSubmit. Reason:
<pre>    Nothing is submitted</pre></p><hr><i><small>Powered by Jetty://</small></i><hr/>

Solution

  • I struggled with this for several hours. Ultimately, this answer to a similar question got me unstuck.

    It seems like Jenkins is expecting form data that has a field called json. The curl command that ultimately worked for me was

    curl -X POST -F 'json={"displayName":"name","description":"a short description"}' \
      http://localhost/job/playground/30/configSubmit