Select Jenkins Node via command line - jenkins

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

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

Jenkins Groovy: Update the labels in all nodes

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?

Is there a way for a docker pipeline file to determine the image of the child node it runs on?

I'd like to be able to dynamically provision docker child nodes for builds and have the configuration / setup of those nodes be part of the Jenkinsfile groovy script it uses.
Limitations of the current setup of jobs means Jenkins has one node/executor (master) and I'd like to support using Docker for nodes to alleviate this bottleneck.
I've noticed there's two ways of using a docker container as a node:
You can use the agent section in your pipeline file which allows you to specify an image to use. As part of this, you can target a specific node which supports running docker images, but I haven't gotten that far as to see what happens.
You can use the Jenkins Docker Plugin which allows you to add a Docker Cloud in Jenkins' configuration. It allows you to specify a label which, when used as part of a build, will spawn a container in that "cloud" from the image chosen in the cloud configuration. In this case, the "cloud" is the docker instance running on the Jenkins server.
Unfortunately, it doesn't seem like you can use both together - using the label but specifying a docker image in the configuration (1) where the label matches a docker cloud template configuration (2) does not seem to work and instead produces a label not found error during the build.
Ideally I'd prefer the control to be in the pipeline groovy file so the configuration is stored with the application (1), not with the Jenkins server (2). However, it suggests that if I use the agent section and provide a docker image, it still must target an existing executor first (i.e. master) which will cause other builds to queue until the current build is complete.
I'm at a point of migrating builds, so not all builds can support using a docker container as the node yet, and builds will have issues when ran in parallel on the master node.
Is there a way for a docker pipeline file to determine the image of the child node it runs on?
There are a few options I have considered but not attempted yet:
Migrate jobs to run on the "docker cloud" until all jobs support running on child container nodes, then move the configuration from Jenkins to the pipeline build file for each job and turn on parallel builds on the master node.
Attempt to add a new node configuration which is effectively a copy of master (uses the same server, just different location). Configure it to support parallel builds, and have all migrated jobs target the node explicitly during builds.

Jenkins workspace not shown for concurrent builds on different nodes

I have one job and two slave nodes. "Workspace" is shown in job overview, but it contains only "Workspace of job on slave2". I run two builds on this job in parallel (one build runs on slave1 and one on slave2)
I tried Jenkins 2.74 and 1.658. I use Windows7 for server and slave. I configured Jenkins Job to "Execute concurrent builds if necessary". Description says
Each concurrently executed build occurs in its own build workspace, isolated from any other builds. By default, Jenkins appends "#" to the workspace directory name, e.g. "#2".
The separator "#" can be changed by setting the hudson.slaves.WorkspaceList Java system property when starting Jenkins. For example, "hudson.slaves.WorkspaceList=-" would change the separator to a hyphen.
I also use "Restrict where this project can be run" with: slave1||slave2
How can i display links to all workspaces of all configured slaves at the same time in jenkins web interface, i thought they will be shown as workspace#1 and so on?

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