Jenkins pipeline agent with label or node call slave node?

flopic picture flopic · Dec 7, 2017 · Viewed 7.9k times · Source

Someone ask about how to create an agent and it create a slave node (here), and I don't know if it's true or no :

agent {
  label 'my-defined-label'
}

and

agent {
  node {
    label 'my-defined-label'
    customWorkspace '/some/other/path'
  }
}

So 'my-defined-label' is just slave name?

Thanks for the answers

Answer

mkobit picture mkobit · Dec 7, 2017

It can match an exact node name, a label, any other supported label expression. For example, java8 && linux, (docker || java) && !windows , and corp-agent-node-01-name are all valid label syntax.

The documentation is clear about how the built in syntax works:

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.

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"