1 | initial version |
To modify the node label in Jenkins once the job has been completed successfully, follow these steps:
Log in to Jenkins and navigate to the job's configuration page.
Click on the "Post-build Actions" tab.
Click on the "Run Scripts" checkbox.
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)
Replace "new-label" with the label you want to assign to the node.
Click on the "Save" button to save the changes.
The node label will be modified the next time a job runs on that node.