How to manage offline slaves using groovy?

Issue

I have some agents connected via ssh and some agents (windows) connected via swarm plugin. Many times these agents go offline and cannot recover. I manually remove them by deleting the questioned agents, e.g. Manage Jenkins > Manage Nodes > NODE_NAME > Delete Agent.

How can I do this via groovy? Basically, get a list of offline agents, check the agent log for some text patterns, and if the strings match, then delete the offline agent.

Environment

  • CloudBees Jenkins Enterprise
  • Swarm plugin
  • Windows

Resolution

We’re not aware of any script that implements the described steps. However, in the Jenkins Script Console you can find some examples similar to what you are looking for.

For example the Monitor and Restart Offline Slaves script can help you to start.

Then, you need to code the second part in which you want to check the agent log and delete the agent if needed.

Have more questions?

0 Comments

Please sign in to leave a comment.