Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 810
Markus Weninger Avatar asked May 14 '18 10:05

Markus Weninger


1 Answers

The && needs to be part of the string, not the logical Groovy operator.

like image 129
Ext3h Avatar answered Nov 01 '22 23:11

Ext3h