Child pages
  • Add a new label to agents meeting a condition

Due to some maintenance issues, this service has been switched in read-only mode, you can find more information about the why

and how to migrate your plugin documentation in this blogpost

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. Unknown User (hayderimran7)

    There is an error in this code.

    The correct way of importing is :


    import jenkins.model.*


    1. Unknown User (mmlegra)

      Thanks for the correction!