How to update a Jenkins job posting config.xml

Recently I wanted to update a few jobs (not defined with a DSL) in Cloudbees, adding to each of them a few properties.

Well, I had some trouble making it work, here are my notes (I used Jenkins 1.651.2.1 but chances are it should work with older and more recent versions, such as jenkins 2)

No security  / no auth

This is the easy part : retrieve and re post the configuration

Simple security : using username and password

I assume now that your Jenkins set up has security set up (http://localhost:8080/jenkins/configureSecurity/ –> enable security)

Screen Shot 2016-05-15 at 22.25.35

It means we now need to authenticate both our requests :

Simple security : with CSRF enabled (crumb)

You would also want to protect your jenkins instance against CSRF attacks (http://localhost:8080/jenkins/configureSecurity/ –> enable csrf crumb)

Screen Shot 2016-05-15 at 22.26.20
Now, it also means your requests need to send a crumb value, either as a parameter or via a header

If you don’t :

You’ll get such errors :

or even  :

Get the crumb value :

You can either the crumb value using a configure job page :

But there’s also a service dedicated to that :

Use the crumb value

Oups, that did not work

I suggest you send the crumb using the headers :

Security, based on cookies (no user / password)

In some installs, such as cloubees, you can’t pass username and password in your requests; I suggest you use the cookies instead.

To retrieve them, inspect the cookies sent by your authenticated browser, for example in chrome :

Screen Shot 2016-05-16 at 10.11.08
And then paste this url in your shell :

Of course, you’ll still need to get the crumb value :

And now you’re ready to post your updated config.xml :

Links