Automating hudson/jenkins via REST and curl – a very small cookbook

As you know, Hudson supports a RESTful-API. So here a small cookbook using curl (running in cygwin). It is very easy, when you are accustomed to it.

#Get the current configuration and save it locally
curl -X GET -o mylocalconfig.xml

#Update the configuration via posting a local configuration file
curl -X POST --data-binary "@mymodifiedlocalconfig.xml"

#Creating a new job via posting a local configuration file
curl -X POST "" --data-binary "@newconfig.xml" -H "Content-Type: text/xml"

Update: Use --data-binary to post the data, else the line-endings won’t be transfered correctly.

Update 2017-08-13: A good post about securing the calls can be found at


14 thoughts on “Automating hudson/jenkins via REST and curl – a very small cookbook

  1. Nice, thank you. I’ve looked around and was unable to find how to use curl to enable a job. Do you happen to know?

  2. hello !
    I try to use PHP curl for sending new config xml file, have you got an idea ?

    Thanks in advance !

  3. If you wanna post with PHP and Jenkins API there is a code work fine for me:

    $xml = file_get_contents(‘’);
    $url = ‘’;
    $ch = curl_init($url);

    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

    $response = curl_exec($ch);

  4. I recently tried this approach to “transfer” some config files from one Hudson instance, to another, but they did not see to “take”. The jobs did (already) have the same name. There were no errors (I could find) but am wondering if you happen to know if there is “machine specific” info in the config files that matter? Or, perhaps “creation time” or similar?

  5. Pingback: How to update a Jenkins job posting config.xml | Anthony Dahanne's blog

  6. I have ‘@’ in my username (e.g, I am getting error says that PORT number starts with ‘T’
    Please help me how to authenticate jenkins with a username which has @.

  7. please update your examples to use HTTPS. it’s not good to encourage submission of credentials over the internet (or anywhere, really) in clear text 🙂


Leave a Reply to markiewb Cancel reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s