Created
April 4, 2018 11:23
-
-
Save dbt4u/1f3e976d44473b004fea326f715d4aea to your computer and use it in GitHub Desktop.
Jenkins Script to get all tools on all slaves
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hudson.model.* | |
import hudson.node_monitors.* | |
import hudson.slaves.* | |
import java.util.concurrent.* | |
import hudson.tools.ToolDescriptor; | |
import hudson.tools.ToolInstallation; | |
jenkins = Hudson.instance | |
TaskListener log; | |
def getEnviron(computer) { | |
def env | |
def thread = Thread.start("Getting env from ${computer.name}", { env = computer.environment }) | |
thread.join(2000) | |
if (thread.isAlive()) thread.interrupt() | |
env | |
} | |
def slaveAccessible(computer) { | |
getEnviron(computer)?.get('PATH') != null | |
} | |
for (aSlave in jenkins.slaves) { | |
def computer = aSlave.computer | |
println "Checking computer ${computer.name}:" | |
def isOK = (slaveAccessible(computer) && !computer.offline) | |
if (isOK) { | |
for (ToolDescriptor<?> desc : ToolInstallation.all()) { | |
for (ToolInstallation inst : desc.getInstallations()) { | |
println ('\tTool Name: ' + inst.getName()); | |
println ('\t\tTool Home: ' + inst.translateFor(aSlave,log)); | |
} | |
} | |
} else { | |
println " ERROR: can't get PATH from slave: node is offline." | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment