assignedNode in config.xml

511 views
Skip to first unread message

J Arrizza

unread,
Jan 22, 2013, 4:56:18 PM1/22/13
to jenkins...@googlegroups.com
Hi,

I'm writing some scripts to keep track of and update the nodes my jobs use. I've come across a problem that I can't seem to resolve. This is a rather long post, but I want to make sure I give you the info you need.

If the "Restrict where this project can be run" is checked on the web page, a node appears in the config.xml:

  <scm class="hudson.plugins.mercurial.MercurialSCM" plugin="merc...@1.41">
    <source>http://cm5/hg/sandbox/v01.0/int</source>
    <modules/>
    <clean>false</clean>
    <browser class="hudson.plugins.mercurial.browser.HgWeb">
    </browser>
  </scm>
  <assignedNode>master</assignedNode>
  <canRoam>false</canRoam>

You can see "assignedNode" sandwiched between the scm and canRoam elements. When you uncheck "Restrict where this project can be run", the element disappears from config.xml. 

So far, so good.

I created a ruby script that gets the xml via the api/config.xml interface. It looks for that node and if it's not found, it adds it (BTW I use nokogiri). But my testing is showing that even if I add the node, the checkbox in the web page doesn't get checked.

Here are some notes:
- If I check the box on the web page and my script just changes the value in it (e.g. from 'master' to 'tm9' and back again), it works perfectly. I run the script, I refresh the web page, and the new value shows up. 

- When the script adds assignedNode, it adds it to the end of the xml root element, but no joy:

  <buildWrappers/>
<assignedNode>tm9</assignedNode></project>

- I tried adding to the front of the xml root element, with no joy:
<?xml version="1.0" encoding="UTF-8"?>
<project>
  <assignedNode>tm9</assignedNode><actions/>
  <description>desc</description>

- When I add the assignedNode, it is actually in the config.xml. After I add it,  update the job via the api/xml, and then do a retrieve using api/xml, the config.xml has the node in it. So Jenkins isn't erasing it or anything like that.

- If my node is in the config.xml and I check the box on the web page, it moves to just under the scm node and it all works correctly again.

- I have done this for several other nodes, checkboxes, etc. and they are working correctly. 

- I have done this extensively for Hudson and it's working correctly too. Note that the assignedNode in Hudson is called appointedNode and has a few extra fields in there.

So, finally, my question: is the assignedNode element position dependent in the config.xml?

John




J Arrizza

unread,
Jan 22, 2013, 5:39:09 PM1/22/13
to jenkins...@googlegroups.com
Update:

I tried a quick change: 
  - find the scm node and 
  - insert the assignedNode element after it. 

Still no joy.

The only thing left that I can see, is there is a missing "\n" after the </assignedNode> when my script inserts the new node:

  <assignedNode>tm9</assignedNode><actions/>

while Jenkins adds the newline:

  <assignedNode>tm9</assignedNode>
  <actions/>

That would imply something very wrong with the XML parser in Jenkins, so it seems very unlikely this is the problem... but I thought I'd ask it anyway.

John

Richard Lavoie

unread,
Jan 22, 2013, 6:00:53 PM1/22/13
to jenkins...@googlegroups.com
it is probably because you need to either reload the config file (I wouldn't do it that way), update the Job object in memory of jenkins or update the plugin object responsible for that option and behavior.

The config is loaded on start and saved when change are made to the internal object from the config page.  It is not reloaded at every step otherwise it would be way too slow and unusable. So doing changes to the conf is most likely useless.

R.

Richard Lavoie

unread,
Jan 22, 2013, 6:05:19 PM1/22/13
to jenkins...@googlegroups.com
It might also depends on the caching added lately to prevent reading too much unnecessary information into memory.

Note that I'm not in front of my computer so what I'm saying in this mail and the last one are somewhat speculations, but some hints on where to look at now to see if you can solve this.

R.

On 2013-01-22, at 17:39, J Arrizza <cppg...@gmail.com> wrote:

J Arrizza

unread,
Jan 22, 2013, 6:13:24 PM1/22/13
to jenkins...@googlegroups.com
Richard,

Thanks for the reply...

I use the "#{@hosturl}/job/#{jobname}/config.xml" url which does not require a reload of the config file. That is mentioned in the Jenkins doc page and in google hits .

And I do have other settings working just fine (for example "Block build when upstream project is building").  Note also that the assignedNode does work fine if the xml element exists and all my script is doing is changing the value.

I do this:

- I run the script
- I go to the Jenkins web page in a browser and refresh the page
- the value (or checkbox or whatever) changes to the new value

In short, it's unlikely a caching problem or I'd see problems elsewhere.
This element is part of native Jenkins so no plugin is involved.

Also an update: I fixed my script to always put the newline in there. So when my Jenkins adds the node it looks like this:

 <scm class="hudson.plugins.mercurial.MercurialSCM" plugin="merc...@1.42">
    <source>http://cm5/hg/sandbox/v01.0/int</source>
    <modules/>
    <clean>false</clean>
    <browser class="hudson.plugins.mercurial.browser.HgWeb">
    </browser>
  </scm>
  <assignedNode>tm9</assignedNode>
  <canRoam>false</canRoam>

and when my script adds the node it looks exactly the same:

 <scm class="hudson.plugins.mercurial.MercurialSCM" plugin="merc...@1.42">
    <source>http://cm5/hg/sandbox/v01.0/int</source>
    <modules/>
    <clean>false</clean>
    <browser class="hudson.plugins.mercurial.browser.HgWeb">
    </browser>
  </scm>
  <assignedNode>tm9</assignedNode>
  <canRoam>true</canRoam>


Does anyone know what's going on then?

John

cjo

unread,
Jan 23, 2013, 9:08:57 AM1/23/13
to jenkins...@googlegroups.com

You will also need to alter the canRoam element from true to false as this controls whether project can be built on any node, or just ones matching the labels.

<canRoam>true</canRoam> --- use any nodes
<canRoam>false</canRoam> --- use defined nodes/labels only

Chris

J Arrizza

unread,
Jan 23, 2013, 2:51:21 PM1/23/13
to jenkins...@googlegroups.com
Thanks Chris!  Works like a charm. 

I am using this set of scripts to migrate 700+ jobs from Hudson to Jenkins, so this was a show stopper.

John
Reply all
Reply to author
Forward
0 new messages