Search code examples
jenkins-pipeline

Label conditions for multiple slave in declarative pipeline of Jenkins


I am trying to use the below:

pipeline {
    agent { label 'slave1 || slave2' }
    stages{
    }
}

When I am using the above format, the job is executing in slave1. But when I am reversing the format i.e agent { label 'slave2 || slave1' }, its still executing on slave1.

Could you please help in clarifying is it the expected way of working. Isn't it something like the label written first, is given first precedence.


Solution

  • This is a feature of Jenkins, not a bug. It tries to be consistent in choosing a slave, as this has a potential of saving some time. For example, on a slave that was used previously, the results of a checkout may still be in the workspace.

    Since slave1 fits both the requirements of 'slave1 || slave2' and 'slave2 || slave1', Jenkins will use it. If it's unavailable or busy, some other slave will be used instead.