Query on triggering build remotely on mutliple conguration project - jenkins

I have a job which executes on 10 platforms (slaves) but when I trigger the job and see its console output, I see a log message saying,
"Started by user <user>
Building remotely on <slave> in workspace: <path>"
Triggering slave1
Triggering slave2
Triggering slave3
Triggering slave4
Triggering slave5
.
.
.
Triggering slave10
The slave in the above messages is any one of the machines from these 10 slaves and sometimes it is any other slave which is not related to this job. How is the mechanism in Jenkins by which a slave is selected to trigger build on all target slaves?

Jenkins will look for any available slave and will assign a build to run on that slave. However, if you want to restrict the build on any particular slave, then you will have to perform the following steps:
Assign label to your slave nodes: To do that, go to Jenkins > Manage Jenkins > Manage Nodes > Select a Slave node > Configure. In this page, you will find a text box called Name. Assign a label/name to it. Perform this activity for all the nodes.
Tie job/project to a particular node(s): Now you have to go to your job's/project's Configure section. Look for the check-box named Restrict where this project can be run. Enable it. As soon as you will enable the check-box, you will see a text box named Label Expression. Assign the name of the node where you want this particular job/project to run. This setting will tie the job to that node and the build will always run on that particular node. Don't forget to click on the '?' mark icon on the extreme left hand side of this option for more details on how you can tie your jobs/projects to multiple nodes etc.

Related

What is the meaning of "Projects tied to {node}" in Jenkins?

I created a Jenkins node / agent / slave and use it for a pipeline. On the node's page there is a list "Projects tied to mynode". What does this mean? When is a project "tied" to a node?
Btw.: If "tied to a project" means here, that the node is used in a project, so why is this list empty?
"Projects tired to ...." will list Freestyle jenkins job which restrict the job executed on this node by specify the node label in job's configuration field:
Restrict where this project can be run -> Label Expression
After you run the job, your job will appear in the "Projects tired to ...." list
I think this list purpose is to let user know the impacted jobs when the node down or before restart or repair the node.
FYI, if the node label filled in Label Expression serviced by more than one machine, the job won't appear in that list. Because job can be executed on any one machine in that group.

Jenkins will look for available node

I have a job in jenkins that run batch file on few nodes. I did it using node parameter. I also added condition that it will run few times. This job is running in parallel but when one host is stack I would like it to continue running this job on other nodes. This is not working. Jenkins is going to the first parameter in the node and trying to run on it and if it is stuck it will not continue to other node. I would like jenkins to look for available node. I tried using multi job plunging and it also didnt work. Also tried working with label but it is not running in parallel....any help ?
I think you can add labels to your node , if you have 4 slaves on ly 2 are windows both will have the label windows , than in your job use the Restrict where this project can be run , add the label value - windows
if you need to run the same job in parallel you can create a matrix job , the same flow will run on several slaves.

Jenkins Multiple Slave node configuration

Our requirement is to we have two slave nodes and one jenkins job. Based on a parameter we must be able to decide where the job has to be run on node1 or node 2. Is there any plugin available?
i did by using build param. From add parameter add 'Node' then set the name of the parameter and other setting. you you have to setup Node[Build machine]. for your information.i added a picture.

How to programmatically determine which Jenkins slave node has been used to run a build?

Let's says I have configured a Jenkins job which can run on a few Jenkins slave nodes (e.g. Node1, Node2, Node3, etc). When a build is started, Jenkins will select an available Jenkins slave to run the Build.
For a Build which has completed, or is currently running, how to programmatically determine which Jenkins slave node has been used to run the Build?
You can use the Jenkins REST API to query an existing build assuming you know the build number:
http://jenkins:8080/job/JOB_NAME/100/api/json?pretty=true
The builtOn field shows the name of the slave which is running/ran the build.
To retrieve only a couple fields of the JSON build information, use the tree parameter:
http://jenkins:8080/job/JOB_NAME/100/api/json?tree=id,timestamp,builtOn&pretty=true
This will return something like:
{
"id" : "2014-12-01_06-18-17",
"timestamp" : 1417443497917,
"builtOn" : "sdev05"
}
Most pages in the Jenkins UI have a REST API link at the bottom indicating they expose information that can be queried programmatically.

Jenkins: Slave selection based on user's choice

I'm trying to configure a jenkins job so that based on the choice of the user the node/slave should be selected.
example : if choice = windows ->slave1
if choice = Linux ->slave2
I've tried with configuration matrix i'm getting error that the nodes are offline.Is there any plugin to do such selections in jenkins
The simplest is to create two build jobs that are then tagged to a specific slave.
When you configure the job you can add labels to it that specify the requirements for this job.
Example:
linux-build, add the label linux
windows-build: add the label windows
Then, when you create the slaves you need to assign them labels as well specifying the capabilities.
Example:
Windows system, add the windows label
Linux system, add the linux label
After this your builds will automatically go to the correct system and you never have to specify anything again. This is better then having to manually specify and trigger a job.
One more advantage, if the job fails you know why.. maybe you linux job always succeeds but you windows job always fails, if you combine this in one job you can't really see this pattern but if you have two separate builds you will immediately see a dark cloud forming over you windows build.
Checkout the following plugin:
https://wiki.jenkins-ci.org/display/JENKINS/NodeLabel+Parameter+Plugin
I used the Jenkins CLI to implement the dynamical slave selection.
1) create two jobs: job A triggers job B
2) at job A, input the followings at Build/Execute Shell
if choice = windows, SERVER=slave1
if choice = Linux, SERVER=slave2
java -jar jenkins-cli.jar -s http_to_jenkins-server:port build buildname -p SERVER_LABEL=$SERVER -v -w --username yourusername --password yourpassword
3) at job B, select "This build is parameterized" and add a String Parameter SERVER.
Hope it helps.

Resources