Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins: skip if node is offline

Tags:

jenkins

I have a task that executes on n machines based on a label. If for some reason, some of these machines are offline, I do not want Jenkins to put them in a queue, and wait until they are online. I would like Jenkins to execute the job on the remaining machines and complete the job. Any suggestions?

Edit 1: I realized that the job is tied to all the machines: Screenshot

I was forced to do this because I needed this job to run simultaneously on all the machines. So, my question remains the same. If some of these machines are offline, I would like to skip the job on them, rather than wait/queue.

Edit 2: Jenkins CLI has a clear queue command. It seems promising for the time.

like image 744
publicRavi Avatar asked Oct 25 '11 15:10

publicRavi


People also ask

How do I skip Jenkins pipeline?

You can skip stages in declarative pipelines using when , so the following should work. stages { stage('Deploy') { when { equals expected: true, actual: Deploy } steps { // ... } } }

How do I skip a build in Jenkins?

use the "Set the build result" step to set the status to "Aborted", this will finish the Jenkins build and will hide the build from the Jenkins dashboard.


1 Answers

A fine solution can be achieved using GroovyAxis Plugin and the following script, that will return Axis list of online slaves only:

def axis = []
for (slave in hudson.model.Hudson.instance.slaves) {
 if (slave.getComputer().isOnline().toString() == "true") {
   axis += slave.name
 }
}
return axis

UPDATE: Since Jenkins 2.0 the node API has been changed, so use Node.toComputer() instead: http://javadoc.jenkins-ci.org/hudson/model/Node.html#toComputer%28%29

def axis = []
for (slave in jenkins.model.Jenkins.instance.getNodes()) {
 if (slave.toComputer().isOnline()) {
    axis += slave.getDisplayName()
 }
}
return axis 
like image 68
Noam Manos Avatar answered Nov 07 '22 09:11

Noam Manos