Child pages
  • Allow broken build claiming on every jobs

Due to some maintenance issues, this service has been switched in read-only mode, you can find more information about the why

and how to migrate your plugin documentation in this blogpost

Skip to end of metadata
Go to start of metadata

After installing the Hudson Claim Plugin, you have to configure each job by manually checking the "allow broken build claiming" option.

Obviously, it can be a bit cumbersome. But here comes the great groovy script console again.
With the following simple script, you can activate the option on every jobs of your server in just one go.

Don't hesitate to give me feedback (and backup your config before playing with those scripts, as always).

import hudson.model.*
import hudson.maven.*
import hudson.tasks.*

for(item in Hudson.instance.items) {
  println("job $item.name")
  hasClaim = false;
  for(p in item.publishers )
  {
    if(p instanceof hudson.plugins.claim.ClaimPublisher)
    {
      hasClaim = true;
    }
  }
  if(!hasClaim)
  {
    println(">>>>>>>> Adding claim right to $item.name")
    item.getPublishersList().add(new  hudson.plugins.claim.ClaimPublisher() );
    item.save()
  }
}

Known quirk:

  • Funnily, if I run this script many times, I see the same item coming back. But when I check inside the job configuration, the checkbox was correctly modified. I don't know where it comes from yet. If you have any idea, just let me know.
  • See the shorter version in the comment below - assuming the plugin has a good hashCode/equals you can just use "replace" instead of searching and adding.  This is essentially the same as the Chuck Norris example.
  • No labels

2 Comments

  1. Unknown User (aheritier)

    A shorter version :

    import hudson.model.*
    import hudson.maven.*
    import hudson.tasks.*
    
    for(item in Hudson.instance.items) {
      println("job $item.name")
      item.publishersList.replace(new  hudson.plugins.claim.ClaimPublisher());
    }
    

    But it doesn't say what it updated

  2. Unknown User (jcarsique)

    The "quirk" comes from the use of item.publishers instead of item.getPublishersList(): your instanceof sentence won't match hudson.plugins.claim.ClaimPublisher$DescriptorImpl (which I guess is returned for all non-Maven jobs, ie FreeStyle jobs). So it finally works because you're systematically re-adding the ClaimPublisher.