1

I am running a DSL script that prints all connected nodes in Jenkins and sets for each of them the Git tool location on the slave.

import hudson.tools.*
import hudson.slaves.*
import jenkins.model.Jenkins

def jenkins = Jenkins.instance
def computers = jenkins.slaves

computers.each{ 
  println "${it.displayName} ${it.nodeName}"
  it.labelString = "blabla"
  println "${it.labelString}"

  def gitToolDescriptor = Jenkins.getInstance().getDescriptor("hudson.plugins.git.GitTool")
  def toolLocation = new ToolLocationNodeProperty.ToolLocation(gitToolDescriptor, " ", "/usr/bin/git")
  def toolLocationProperty = new ToolLocationNodeProperty(toolLocation as List)
  it.nodeProperties.add(toolLocationProperty)
  it.save()
}

The path locations are set properly when checking the Node configuration via Jenkins UI. Still, it seems that the paths are not updated properly, since when I try to clone a repo on the slave I get:

/usr/local/git/bin/git rev-parse --is-inside-work-tree # timeout=10

I have to go back to the node configuration and press manually the "Save" button and the path updates properly.

/usr/bin/git rev-parse refs/remotes/origin/

Any clues are welcomed!

amicl
  • 11
  • 2

1 Answers1

0

Solved in the meantime. Maybe will help someone else in the future. The issue was that all the slave objects I was getting were SwarmSlave type, so I had to do first a type-safe cast Node slave = it.asNode(). And Bingo!

amicl
  • 11
  • 2