Skip to content

Instantly share code, notes, and snippets.

@stronk7
Last active March 11, 2023 14:45
Show Gist options
  • Save stronk7/75c61e529906e31ca0ade8bf054bef01 to your computer and use it in GitHub Desktop.
Save stronk7/75c61e529906e31ca0ade8bf054bef01 to your computer and use it in GitHub Desktop.
Check controller/workers agent versions
import jenkins.model.*
import hudson.remoting.Launcher
import hudson.slaves.SlaveComputer
def expectedVersion = Launcher.VERSION
for (computer in Jenkins.instance.getComputers()) {
if (! (computer instanceof SlaveComputer)) continue
if (!computer.getChannel()) continue
def version = computer.getSlaveVersion()
if (!expectedVersion.equals(version)) {
println "${computer.name} - expected ${expectedVersion} but got ${version}"
if (computer.node.labelString.contains('kubernetes')) {
println " - this is acceptable for kube (docker image based) workers."
} else if (computer.name.contains('attic.com')) {
println " - kill the 'java -jar agent.jar...' process. It will respawn in 3 minutes. <<== Eloy"
println " - PLEASE, ensure that the worker in NOT RUNNING ANY job, before"
println " restarting the slave. If not, those jobs in the worker will"
println " die with CONNECTION PROBLEM."
} else {
println " - it's recommended to kill '/usr/local/bin/jenkins.sh' in the iron"
println " worker to force it to get matching agent version from controller."
println " (sudo service jenkins-slave restart should be also ok)"
println " - PLEASE, ensure that the worker in NOT RUNNING ANY job, before"
println " restarting the slave. If not, those jobs in the worker will"
println " die with CONNECTION PROBLEM."
}
} else {
println "${computer.name} - ok - got expected ${version}"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment