Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To modify the node label in Jenkins once the job has been completed successfully, follow these steps:

  1. Log in to Jenkins and navigate to the job's configuration page.

  2. Click on the "Post-build Actions" tab.

  3. Click on the "Run Scripts" checkbox.

  4. In the "Script" field, enter the following Groovy script:

import hudson.model.Computer
import hudson.model.labels.LabelAtom

def computer = Computer.currentComputer()
def label = new LabelAtom("new-label")

computer.assignedLabels = computer.assignedLabels.minusAll(computer.getAssignedLabels())
computer.assignedLabels = computer.assignedLabels.plus(label)
  1. Replace "new-label" with the label you want to assign to the node.

  2. Click on the "Save" button to save the changes.

The node label will be modified the next time a job runs on that node.