4

I am creating a list of Jenkins jobs for sanity test of our Jenkins build environment. I want to create layers of jobs. The first layer of jobs will check the environment, e.g. if all slaves are up, the 2nd layer then can check the integration to other tools such as GitHub, TFS, SonarQube, then the 3rd layer can run some typical build projects. This sanity test can also be used to verify the environment after any major changes to the Jenkins servers.

We have about 10 slaves created on two servers, one Windows and one Linux. I know I can create a job to run on a specific slave, therefore test if the slave is online, but this way I need to create 10 jobs just to test all slaves. Is there a best approach to check if all slaves are online?

Jirong Hu
  • 2,315
  • 8
  • 40
  • 63
  • You could potentially run a job on master, which is just a script that scrapes the API to get a very basic idea of "is every slave online".... http://jenkins_url/computer/api/json ....a few properties within there that Jenkins exposes, which is stuff like "is the slave online". – Arran Jan 06 '16 at 12:28

1 Answers1

6

One option is to use Jenkins Groovy scripting for a task like this. The Groovy plugin provides the Jenkins Script Console (a useful way to experiment) and the ability to run groovy scripts as build steps. If you're going to use the Script Console for periodic maintenance, you'll also want the Scriptler plugin which allows you to manage the scripts that you run.

From Manage Jenkins -> Script Console, you can write a groovy script that iterates through the slaves and checks whether they are online:

for (node in Jenkins.instance.nodes) {
  println "${node.name}, ${node.numExecutors}"
  def computer = node.computer
  println "Online: ${computer.online}, ${computer.connectTime} (${computer.offlineCauseReason})" 
}

Once you have the basic checks worked out, you can create either a standalone script in Scriptler, or a special build to run these checks periodically.

It often takes some iteration to figure out the right set of properties to examine. As I describe in another answer, you can write functions to introspect the objects available to scripting. And so with some trial and error, you can develop a script performs the checks you want to run.

Community
  • 1
  • 1
Dave Bacher
  • 15,652
  • 3
  • 63
  • 86