Jenkins Groovy: Update the labels in all nodes - jenkins

I have a few hundred jenkins nodes and need to update the labels in all of them.
It seems the easiest would be to run a groovy script in the Jenkins master script console that would add the extra label to each node's config.
Question: How would one do this in groovy?

Related

Is there any way to create a node(slave) automatically to build jobs of particular project?

As the topic's title, I would like to create Jenkins node automatically to build jobs for a particular project. Example: I have 3 projects (Java, NodeJS, .NET) and I would like to build these projects on separate nodes. My scenario here is:
When I start to build one of these project, Jenkins will check the node with given label name(node name), if the node doesn't exist then Jenkins will create one with given label name.
My question here is how to create a Jenkins node automatically with Jenkins pipeline?
If you referring on demand node scale/down, I am not sure how to do it, but better and long term solution for managing multiple runtime/dependencies would be to execute your pipeline stages into the containers, which is what most of the CI/CD tools does now days

Select Jenkins Node via command line

All our jenkins nodes have various labels. Jenkins jobs are restricted to some assortment of those labels. From the command line (Jenkins CLI), I want to override that restriction for a specific build which I am kicking off from the command line.
That is, for this one build which I am kicking off from the command line, I want Jenkins to use node ABC even though the build is restricted to a label which does not include node ABC.
We do not use piplines

Jenkins - How to install a setup of plugins on an agent if I want a slave to do a specific task

In Jenkins, I'm trying to setup Controller and Agent nodes.
I've two questions here.
I want to understand how to install a setup of plugins on an agent?
2 Can I have different agent with different plugins so that I can assign a agent(based on the plugins installed) for a specific build?
Did you figure this out?
Plugins are installed on master, but jobs steps invoke the plugin on the agent (slave) where run. You can have many agents, but for example if you run a job invoking a windows batch cmd on a linux node, job will just fail.
Use labels on the nodes and your jobs to restrict where a job can run. Search http://plugins.jenkins.io for "label" for some helpful plugins to manage labels. Prefer capability/feature labels instead of tying to hostnames.
Generally, a plugin has a global configuration, and job specific parameters to configure. Not likely to have node by node plugin config but would be plugin specific in any case

Jenkins - How to run one housekeeping job on all nodes (slaves + master)

I have Jenkins setup of 6 Slaves and master, all windows machines. Now I have a housekeeping Jenkins job which I want to periodically run on all the slaves and master, as this job does following tasks
Delete unused temporary files.
Delete unwanted processes, as some of the tests are leaking processes (why leak is different question).
Set certain environment variables, as sometimes I want to push environment variable changes to all machines.
Any idea how can I force Jenkins to run this one job on all slaves and master once every day? As a work around I can create multiple Jenkins job and mark each one to run on one particular slave or master, but I would rather avoid having so many duplicate jobs.
The Node and Label Parameter plugin allows you to parameterize where a job should be run. The job can be run on more than one node -- each node shows up as a separate execution in the job's build history. When multiple nodes are selected, you can configure whether the job should continue to run on other nodes if an execution fails.
I had a similar need, but using the Node and Label Parameter Plugin didn't seem quite right, as I do not want to parameterize my cleanup jobs.
I found a more satisfying answer in this post and thought it would also benefit to this question: Jenkins - Running a single job in master as well as slave.
Here is some documentation on how to configure a "Matrix project": https://wiki.jenkins.io/display/JENKINS/Building+a+matrix+project.
What you are looking for is the "Slave axis". It's not very well documented in the page above, but it appears as an option of the "Add axis" menu whenever there are more than one node. Here's a screenshot of the interesting part:
Updates according to recent Jenkins
Pipeline type:
On "Configuration" page for pipeline:

How to label to restrict build to slave nodes to use by using parameterized build

For my Jenkins job, I have setup an environment parameter which tells my build script which configuration to use. I also have slave nodes running on each of my environments to build and deploy my application.
I have tried used the "Restrict where this project can be run" with the value
buildnode-${ENV}
where ENV is the name of my parameter. This doesn't seem to work as label does not perform substitution.
I have also tried the NodeLabel Plugin, which allows me to define which nodes to run the job from. However, this will create two separate selections:
Is there a way to tie this two together, so when I select QA environment, for example, the slave node for the QA server is choose to run the build?
You can try the following work-around: have two builds - A and B. A will set up the environment, save it into a file, and pass the file as a parameter to build B, along with the name of the node on which to run (the parameters will be passed via Parameterized Trigger plugin). B will read the environment (via EnvInject plugin) and run the build on the node passed as the other parameter (you do need to use NodeLabel plugin).

Resources