Jenkins: skip if node is offline

后端 未结 2 1410
悲哀的现实
悲哀的现实 2020-12-17 22:32

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

相关标签:
2条回答
  • 2020-12-17 23:19

    If the task is attached in a way that it only runs on a particular node, it will not be able to run it on other machines.

    If that isn't the case then the task will run on any of the available executors, this is the default behaviour.

    So in order check to see if the task can run on other nodes go to the job > configure and check the setting of the following.

    enter image description here

    If that is disable on the task, then you will need to check the nodes that they accept any jobs this can be found under the node settings. It should read like the following.

    enter image description here

    Goodluck.

    0 讨论(0)
  • 2020-12-17 23:25

    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 
    
    0 讨论(0)
提交回复
热议问题