Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to require two or more labels for a jenkins job?

Tags:

jenkins

I don't know how it happens that the option named "Restrict where this project can be run" from Jenkins seems to allow only a single value inside "Label Expression" field.

I tried lots of combinations in order to add more than one label and I wasn't able to find any way to put two.

I need to mention that I need AND between these labels.

The irony is that this option even has an Info button which loads some documentations, which is missing to say how an expression is supposed to look like. Another small nail in the Jenkins UX coffin. On this one neither Google helped.

like image 389
sorin Avatar asked Jan 09 '23 00:01

sorin


1 Answers

There is a Jenkins bug causing the help text not to be shown. It is present since 1.585 and fixed since 1.621 (or 1.609.3 respectively).

Here is the help text:

If you want to always run this project on a specific node/slave, just specify its name. This works well when you have a small number of nodes.

As the size of the cluster grows, it becomes useful not to tie projects to specific slaves, as it hurts resource utilization when slaves may come and go. For such situation, assign labels to slaves to classify their capabilities and characteristics, and specify a boolean expression over those labels to decide where to run.

Valid Operators

The following operators are supported, in the order of precedence.

(expr) parenthesis

!expr negation

expr&&expr and

expr||expr or

a -> b "implies" operator. Equivalent to !a|b. For example, windows->x64 could be thought of as "if run on a Windows slave, that slave must be 64bit." It still allows Jenkins to run this build on linux.

a <-> b "if and only if" operator. Equivalent to a&&b || !a&&!b. For example, windows<->sfbay could be thought of as "if run on a Windows slave, that slave must be in the SF bay area, but if not on Windows, it must not be in the bay area."

All operators are left-associative (i.e., a->b->c <-> (a->b)->c ) An expression can contain whitespace for better readability, and it'll be ignored.

Label names or slave names can be quoted if they contain unsafe characters. For example, "jenkins-solaris (Solaris)" || "Windows 2008"

like image 118
Oliver Gondža Avatar answered Jan 14 '23 22:01

Oliver Gondža