I have recently started using the Jenkins Swarm plugin which grants us the ability to allow dynamic agents to join the cluster, I am thinking about writing a plugin that would perform a set of actions before the agent is allowed to take jobs, irrespective of the 'mode' or 'label' assignments.
When a new agent joins, I would like to be able to run a set of tests, or jobs that would signify whether or not the agent is capable of taking on real jobs. Things such as: checkout code from scm, run a gradle build, etc
My thinking for implementation:
- When an agent joins the cluster, don't allow it to take any jobs until it is vetted
- To vet the agent, a set of jobs would all be required to pass (run and return a success)
More implementation details:
1) When an agent joins, immediately set its mode to 'exclusive' and change all labels to <label>_candidate
2) Do a search for any job with the <label>_candidate restriction and run those jobs
3) If those jobs are all successful, remove the <label>_candidate label and set the mode back to its original setting
My questions:
1) Is there a better way to do this?
2) What extension points should I look at to do this? So far I have started looking at hudson.slaves.ComputerListener but am unsure if I can hook in early enough to prevent any jobs from running on the newly added agent before changing it
3) Does a plugin already exist that does this or have similar behavior?
Any guidance would be appreciated.
Thanks!
Antonio