nodelabel plugin and groovy

71 views
Skip to first unread message

Niksan

unread,
Jan 19, 2016, 12:35:09 PM1/19/16
to Jenkins Users
I'm trying to control where jobs are run from a groovy script, it's an edge case that I have to run on all nodes in a label rather than what's free.  I was hoping I could use the nodelabel plugin to do this.

On my slave job I have a label parameter, named and defaults to my label that a lot of slaves are hooked up to (Distributed_build), I run as run on all nodes matching the label, ignore offline nodes and run regardless of result.

I put a machine in there that's part of the label cluster to see if I could force to a node (Machine_1) so I could visually see the jobs queued for that node rather than using a free node part of the label cluster, but it seems to run all builds on the label cluster regardless. Am I doing something wrong or just assuming incorrectly how the plugin works?


In my source job I have the following groovy script.

def nodes = [
  "Distributed_build",
  "Distributed_build",
  "Distributed_build",
  "Distributed_build",
  "Distributed_build",
  "Machine_1",
  "Machine_1",
  "Machine_1",
  "Machine_1"
];

def targetJobName = "SuperDuper Job" 
def jobToTrigger = Jenkins.instance.getItem( targetJobName ) 

def i=1
nodes.each {
  node ->
    if(jobToTrigger!=null) {
      def futureJob = jobToTrigger.scheduleBuild( 2, new Cause.UpstreamCause( build ), new ParametersAction( [
        new StringParameterValue( 'Distribution_Label', node ),
        new StringParameterValue( 'Build_Command_Line', i.toString() )
      ] ) )
      println(futureJob)
    }
    println(node)
    i++
}

Victor Martinez

unread,
Jan 20, 2016, 3:15:29 AM1/20/16
to Jenkins Users
Hi,

 Have you tried to use the matrix project type? you can run same steps in different slaves/labels at the same time.

Cheers

Niksan

unread,
Jan 20, 2016, 3:40:59 AM1/20/16
to Jenkins Users
The matrix job differs in its workspace layout so doesn't play ball, a square peg for a round hole.

Niksan

unread,
Jan 20, 2016, 6:13:24 AM1/20/16
to Jenkins Users
Parameters matter, the fix is obvious in hindsight.

new StringParameterValue( 'Distribution_Label', node ),

should be

new LabelParameterValue( 'Distribution_Label', node ),

Happy days \o/
Reply all
Reply to author
Forward
0 new messages