Child pages
  • Add a new label to slaves meeting a condition
Skip to end of metadata
Go to start of metadata

This script shows how to alter the slave nodes' label membership. In this case we create a new label if the existing label contains a string. It has been tested from the Jenkins command window.

import jenkins.model.*
//Groovy script to add a label to all slave nodes having labels matching a certain specification.

for (slave in jenkins.model.Jenkins.instance.slaves) {
    oldLabelName = slave.getLabelString()

    if (oldLabelName.contains('WIN2012')) {

        newLabelName = oldLabelName + " " + "WIN2012.X"
  • No labels


  1. There is an error in this code.

    The correct way of importing is :


    import jenkins.model.*


    1. Thanks for the correction!