Customize Jenkins pipeline stage view - jenkins

How can i add the little blue tags to stage view in a Jenkins Pipeline?

I was searching for this as well and found the following after reading Hatim's answer:
The line that was supposed to show the node label is commented out:
source
The referenced issue JENKINS-33290 is Resolved with the last comment:
Resolved by removing the functionality, since a correct implementation imposes unacceptable complexity and overhead.
So I'm afraid it's not coming back soon and all those screenshots online are outdated.

Is the name or label of the node used.
Please refer to this
https://jenkins.io/doc/pipeline/steps/workflow-durable-task-step/
node: Allocate node
Allocates an executor on a node (typically a slave) and runs further code in the context of a workspace on that slave.
label
Computer name, label name, or any other label expression like linux && 64bit to restrict where this step builds. May be left blank, in which case any available executor is taken.
In this case, the stage is executed in the master, if you configure your jenkins pipeline to be executed in differents plateforms (master-slaves), then you will be able to see the label of your slaves environement.

Related

How to choose between two agents for high-availability in Jenkins pipeline

I have several agents configured in Jenkins.
For one of my pipeline jobs execution, I wish to choose between two of my agents i.e. MYHOST11-ANSIBLE-SLAVE and MYHOST22-ANSIBLE-SLAVE which ever is available. Thus, if MYHOST11-ANSIBLE-SLAVE is unavailable my Jenkins pipeline job should switch to using MYHOST22-ANSIBLE-SLAVE
Can you please suggest what changes do I need in my below pipeline code ?
pipeline {
agent {
node {
label 'MYHOST11-ANSIBLE-SLAVE'
}
}
stages {
stage('Precheck') {
steps {
sh "echo Im from Jenkins>/tmp/jenkinsmoht.txt"
Note: I want my pipeline to choose only between the two agents I mentioned as only they have ansible with my pipeline invokes.
Other agents don't have ansible thus my pipeline would fail.
I think you have your nomenclature strategy a little skewed...
Let's say you have two nodes, named "HOST11" and "HOST22". Those two have ansible installed. Other nodes (eg "HOST33") do not. Those are the names of the Nodes, reflective of the Hosts the agents run on.
You want to configure your Nodes (/computer/<NodeName>/configure) with "labels" according to their characteristics, in this case "ansible", thus creating a "pool of nodes" of similar configuration.
You then use the label of the characteristic ("ansible") to assign the job to the pool of servers with that corresponding label (and characteristic). By assigning labels to nodes, you can specify the resources you want to use for specific jobs, and set up graceful queuing for your jobs.
eg:
agent {
node {
label 'ansible'
}
Jenkins will then pick the first available node with the matching label and run there, unless that node is not available. It will then try the next. If none are available, the job will remain queued.
If you choose to use a Host Name (which in truth is also just a "label", then you can only run on that one node).
Another distinction: "Available Node" in Jenkins implies on-line. If all executors are busy, it is still "available". Jenkins jobs are "sticky", it will wait until a node it has previously run on has an available executor. That can also result in the first node being overloaded. If that's a problem, look to install the "Least Load" plugin which will act as a load balancer using various criteria.
See this post to further constrain jobs using multiple labels.
ps: If your nodes are similar but not identical, you may be use the "Node Properties" or the "Slave Setup" plugin to make them transparently compatible to your job (eg: set VAR to different values/paths).

Jenkinsfile in a node with hostname

I would like to execute my job in a remote node passing the domain name as node arg.
Someone knows how to build this jenkinsfile?
I can't execute on the below way
node('jenkins.mydomain.com') {
build 'remote_exec'
}
There are actually two major issues within your two lines of code :-)
node('jenkins.mydomain.com') {
This will build on a build agent with the label jenkins.mydomain.com. If you have only one build agent with this label given, this should work. But it's not the hostname! (Note: I'm not entirely sure if dots are allowed, but you could call it also whateverserver).
So this would allocate an executor slot (to run the code within the closure) on a build agent matching the given label...
build 'remote_exec'
and then trigger yet another build for the job called remote_exec. This job (assuming it exists and you don't have this as a third issue^^) will then be built on an agent matching its own labels, ignoring the one given in the node(label) step.
If you want that the remote_exec job runs on a specific build agent only, then add the node step there!

NodeLabel Parameter Plugin not working with pipelines

My current setup is not working well with the NodeLabel Parameter Plugin and I am wondering if I am missing something, I find the documentation at https://wiki.jenkins.io/display/JENKINS/NodeLabel+Parameter+Plugin incomplete (e.g. it is missing any info on node configuration when using label restriction).
My setup :
- nodes are setup with the options : 1) only build job with label expressions matching this node 2) label field set to 'mytest'
- pipeline definition in jenkins gui set with the following option checked 'This project is parameterized', I have added the label default value to 'mytest'. I kept the default name to 'executor label' based on the documentation (guessing this is not relevant though)
Result : the job gets stuck, output below
[Pipeline] node [...all my agents listed here] is reserved for jobs with matching label
I am using a shared library for my pipeline, I also have tried to add the label in the node object :
node{ label 'mytest' }
same issue. I m not finding much help online - again I am surprised by the lack of details in the Jenkins plugin documentation.
Any suggestion? thanks

How can I select some projects to be eligible to be built by slaves

I've created successfully my 1st Jenkins slave, but I don't want to be used to all the projects, so I've chosen the {{Only selected projects}} option.
But how can I choose the projects?
I've looked at Jenkins management, and the configuration of a project, and I don't see the needed setting.
You tie jobs to slaves in the jobs' configuration: go to ${jenkins url}/job/${job name}/configure and look for the Restrict where this project can be run field in the general settings:
You can type names of slaves there, or even better, use tags assigned to slaves. You can use logical expressions like || and &&, too.
To expand on ameba's answer you can set labels for a node in the node configuration settings and therefore label nodes with the toolchains or tools that you require.
Then in jenkins-pipeline you can do the following:
node('TOOL label')
{
stage('build using TOOL') {
}
}
the node section tell jenkins to find a node with that label and to use it for the following block of code.

Simple way to temporary exclude a job from running on a node in a label group

I wan't to be able to temporary exclude a specific job from running on a node in a label group.
jobA, jobB, jobC are tied to run on label general
nodeA,nodeB,nodeC have the label general on them.
Let's say that jobA starts to fail consistently on nodeA.
The only solutions that I see today are taking nodeA offline for all jobs or reconfigure many jobs or nodes which is pretty time consuming. We are using JOB-DSL to configure the jobs so changing in the job configuration requires a checkin.
An ideal situation for us would be to have a configuration on the node:
Exclude job with name: jobA
Is there some easy way to configure that jobA should temporarily only run on nodeB and node C and that jobB/C should still run on all nodes in label general?
Create a parameterized job to run some job-dsl configuration. Make one of the parameters a "Choice" listing the job names that you might want to change.
Another parameter would select a label defining the node(s) you want to run the job on. (You can have more than one label on a node).
The job-dsl script then updates the job label.
This groovy script will enable/disable all jobs in a folder:
// "State" job parameter (choice, DISABLED|ENABLED)
def targetState = ('DISABLED'.equalsIgnoreCase(State))
// "Folder" job parameter (choice or free-text)
def targetFolderPath = Folder.trim()
def folder = findFolder(jenkins, targetFolderPath)
println "Setting all jobs in '${folder.name}' to '${targetState}'"
for (job in folder.getAllJobs()) {
job.disabled = targetState
println "updated job: ${job.name}"
}
I just came across the same issue, I want the job to run on the device with lable, say "lableA", but do not want it to run on device with lable "lableB".
We may try this:
node(nodeA && !nodeB) {
}
Refer to: https://www.jenkins.io/doc/pipeline/steps/workflow-durable-task-step/#node-allocate-node
you can also use NodeLabel Parameter Plugin in jobA. Using this plugin you can define nodes on which the job should be allowed to be executed on. Just add parameter node and select all nodes but nodeA.
https://wiki.jenkins-ci.org/display/JENKINS/NodeLabel+Parameter+Plugin
For a simple quick exclude, what I think the original question refers to as "The only solutions that I see today are ... reconfigure ... jobs or nodes" see this other answer: https://stackoverflow.com/a/29611255/598656
To stop using a node with a given label, one strategy is to simply change the label. E.g. suppose the label is
BUILDER
changing the label to
-BUILDER
will preserve information for the administrator but any job using BUILDER as the label will not select that node.
To allow a job to run on the node, you can change the node selection to
BUILDER||-BUILDER
A useful paradigm when shuffling labels around.
NOTE that jobs may still select using the prior label for a period of time.

Resources