How to create a job using the REST API and cURL?


I would like to be able to create a job remotely using the Jenkins REST API and cURL. This provides a workaround for JENKINS-12543, that doesn’t require SSH Key Authentication.


  • CloudBees Jenkins Enterprise
  • Remote Access API
  • cURL


First, create a job using the UI. This job can be used to create a base config that can be used to create new jobs.

To retrieve the job config.xml that you made via the UI, to use for creating new jobs:

curl -X GET -u username:API_TOKEN -o mylocalconfig.xml

Obviously, replace:

  • username:API_TOKEN with your username and password/API_Token
  • with your Jenkins URL
  • test with the name of the job that you created via the UI

You can now modify this config file locally to suit for needs as required.

Once ready, to use this config to create a new job:

curl -s -XPOST '' -u username:API_TOKEN --data-binary @mylocalconfig.xml -H "Content-Type:text/xml"

Obviously, replace:

  • username:API_TOKEN with your username:password
  • with your Jenkins URL
  • yourJobName with the name you would like to give the new job name

If the output message is an error message like

Error 403 No valid crumb was included in the request

means that the CSRF Protection is enabled in the Jenkins instance, thus the curl command requires the crumb field. In that case, try this:

CRUMB=$(curl -s ',":",//crumb)' -u username:API_TOKEN)
curl -s -XPOST '' -u username:API_TOKEN --data-binary @mylocalconfig.xml -H "$CRUMB" -H "Content-Type:text/xml"

Note: Jobs created though the REST API are subjected to migration by the RunIdMigrator on the next Jenkins startup. Please have a look at Jenkins Startup logs show RunIdMigrator logs.

See Remote Access API for more.

Have more questions?


  • 2
    Peter Lai

    none of your api makes sense at all, it needs to completely rewritten, 

    http://localhost:9080/createItem/api meant to tell you the json you need to post, well -> "requires a post@ e.g. no documentation at all, when you try to submit a json, you just get no mode given, wtf is a mode, where is this written anywhere. 



Please sign in to leave a comment.