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.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2022-10-13 11:00:00 +0000
Seen: 20 times
Last updated: May 13 '21
How to choose specific parameters while selecting inputs in Jenkins (Groovy) Pipeline?
What are the typical approaches found in a Gradle build script?
How can a list of objects in Groovy be created from Json?
How to provide the workspace path as a file to setReportDir in XmlTestRunListener using groovy?
What is the method to invoke a function within Gradle's `pluginManagement {}` section?
What is the reason for the convertibility of variable types in a Groovy class?