Created
September 2, 2015 00:40
-
-
Save carpnick/3f72bb3b127d6c07f8b0 to your computer and use it in GitHub Desktop.
This file contains 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.slaves.* | |
import jenkins.model.* | |
import jenkins.slaves.* | |
slave = Jenkins.instance.getNode('adapt-lin-s1') as Slave | |
if(slave == null) { | |
return null | |
} | |
current_slave = [ | |
name:slave.name, | |
description:slave.nodeDescription, | |
remote_fs:slave.remoteFS, | |
executors:slave.numExecutors.toInteger(), | |
usage_mode:slave.mode.toString().toLowerCase(), | |
labels:slave.labelString.split().sort(), | |
environment:new java.util.HashMap<String,String>(slave.nodeProperties.get(EnvironmentVariablesNodeProperty.class)?.envVars), | |
connected:(slave.computer.connectTime > 0), | |
online:slave.computer.online | |
] | |
// Determine retention strategy | |
if (slave.retentionStrategy instanceof RetentionStrategy.Always) { | |
current_slave['availability'] = 'always' | |
} else if (slave.retentionStrategy instanceof RetentionStrategy.Demand) { | |
current_slave['availability'] = 'demand' | |
retention = slave.retentionStrategy as RetentionStrategy.Demand | |
current_slave['in_demand_delay'] = retention.inDemandDelay | |
current_slave['idle_delay'] = retention.idleDelay | |
} else { | |
current_slave['availability'] = null | |
} | |
builder = new groovy.json.JsonBuilder(current_slave) | |
println(builder) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment