Ask Your Question
3

How to modify the node label in Jenkins once the job has been completed successfully?

asked 2022-10-13 11:00:00 +0000

devzero gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-05-13 21:00:00 +0000

pufferfish gravatar image

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.

edit flag offensive delete link more

Your Answer

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

Add Answer


Question Tools

Stats

Asked: 2022-10-13 11:00:00 +0000

Seen: 20 times

Last updated: May 13 '21