Skip to content

Instantly share code, notes, and snippets.

@carpnick
Created September 2, 2015 00:40
Show Gist options
  • Save carpnick/3f72bb3b127d6c07f8b0 to your computer and use it in GitHub Desktop.
Save carpnick/3f72bb3b127d6c07f8b0 to your computer and use it in GitHub Desktop.
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