Jenkins Multiple Slave node configuration - jenkins

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.

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.

Jenkinsfile - Build Agents questions

I have following questions about Jenkins build agents:
Question 1: agent any means that "Execute the Pipeline, or stage, on any available agent" - how to check what are list of available agents and what are their capabilities (e.g. one agent can build maven, another not...)?
Question 2: agent { label 'docker' } means that I will use agent called "docker" - how to find out is that agent actually exists? Where to find it?
Thanks for help :)
Jenkins allows you to have multiple agents (nodes or slaves) but when you install jenkins the only agent configured is the master.
It is quite simple to configure new nodes, please refer to one of these guides:
https://wiki.jenkins.io/display/JENKINS/Step+by+step+guide+to+set+up+master+and+slave+machines+on+Windows
https://www.packtpub.com/mapt/book/application_development/9781783553471/7/ch07lvl1sec47/managing-jenkins-master-and-slave-nodes
http://www.donaldsimpson.co.uk/2011/10/06/jenkins-slave-nodes/
When you are setting up a new node you can assign labels to it so that you can then use to perform specific tasks on that node from a pipeline, for example.
So answering your questions:
This setting can be done using labels.
Example:
All nodes with maven have a label, eg "maven".
Then running something like agent { label 'maven' } will only execute in one of this nodes.
You can list all available nodes and check the configurations for each one in Manage Jenkins > Manage Nodes.

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.

Query on triggering build remotely on mutliple conguration project

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.

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