Jenkins will look for available node - jenkins

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.

Related

how can I use a jenkins job to loop another jenkins job

I have a requirement where I need 2 Jenkins job, One job to take user parameters (eg: user chooses number 10 which means I need to run second job 10 times)
second job will be the actual execution of test automation.
The loop will continue irrespective of the result (pass/fail) of previous iteration
just trying to represent this as a Snippet,
Job A :
User input = 10
for(num<=10){
Job B(num)
}
Job B :
execute(num)
P.S: If there is a solution where I can achieve this in a single job, Please suggest
You can use Jenkins upstream/downstream concept, please refer below url:-
Jenkins Upstream/Downstream Linking
You can do it:
You can use the same solution for Linux and Windows machine (in windows write cmd syntax and in Linux Bash)
You create a loop for example in Bash:
!/bin/bash
for i in {1..5}
do
curl
done
If you do not know CURL please use the link below.
https://serverfault.com/questions/888176/how-to-trigger-jenkins-job-via-curl-command-remotely

How to use multiple labels to select a node in a Jenkins Pipeline script?

Intro:
We are currently running a Jenkins master with multiple slave nodes, each of which is currently tagged with a single label (e.g., linux, windows, ...)
In our scripted-pipeline scripts (which are defined in a shared library), we currently use snippets like the following:
node ("linux") {
// do something on a linux node
}
or
node ("windows") {
// do something on a windows node
}
Yet, as our testing environment grows, we now have multiple different Linux environments, some of which have or do not have certain capabilities (e.g., some may be able to run service X and some may not).
I would like to label my slaves now with multiple lables, indicating their capabilities, for example:
Slave 1: linux, serviceX, serviceY
Slave 2: linux, serviceX, serviceZ
If I now need a Linux slave that is able to run service X, I wanted to do the following (according to this):
node ("linux" && "serviceX") {
// do something on a linux node that is able to run service X
}
Yet, this fails.
Sometime, also a windows slave gets selected, which is not what I want to achieve.
Question: How can i define multiple labels (and-combined) based on which a node gets selected in a Jenkins scripted pipepline script?
The && needs to be part of the string, not the logical Groovy operator.

Jenkins/Hudson CLI API get the node that the script is running on using Groovy

I am using the Hudson API in Jenkins written in groovy and i want to get the labels of the current slave that the script is running on. I know i can get the labels that were passed in but that's not what I want. I can get all the slaves using
hudson.model.Hudson.instance.slaves
but how do I know which one I am running on? once I have the node I can change the label using myslave.getAssignedLabels() but getting that node seems to be an issue.
any suggestions?
Use getAssignedLabels from Node class:
Computer.currentComputer().getNode().getAssignedLabels()

[Jenkins]Why User-Defined axis doesn't work with slaves

I created a multi-configuration project that is running a couple of automation tests. I have an user-defined axis that is running on a single node and I want to parallelize the process.
I have the following configuration:
My problem is that both jobs will be running one the same node.
At first it wil start "EU_Washroom" and then "EU_Linen".
"EU_Linen" is not running on the 5th(JenkinsQFT5) node, instead is running on 4, disregarding the combination filter(QF_SCRIPT_NAME == "EU_Linen" && slave=="Jenkins-QFT5").
Also at the end of the name of the job, the name of the node is added.
Is it a bug or am I doing something wrong? I'm using Jenkins version 1.598
EDIT:
I deleted the combination filter and all 4 combinations were running on a single node.
Both nodes are set with the usage: "Utilize this node as much as possible"
EDIT #2:
I deleted the user-defined Axis, and let only the Slave-Axis and it acts the same.
The console of the job that should ran on Jenkins-QFT5: Building remotely on Jenkins-QFT4 in workspace c:\JenkinsSlave\lib\workspace\8.03.08-QF-tests\TestParalelFor8\Jenkins-QFT5
In Jenkins ver. 2.5 this is working well.
It was a bug in Jenkins v1.598

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