0

I have 2 agents, one is production and the other is DR. I would like my pipelines to be able to run on either dynamically and randomly. So job number 1 might run on agent 1 and job number 2 might run on Agent 2 or it could be that odd jub numbers can run on a particular agent and even number jobs can run on a differnt agent.

Thanks in advance.

learner
  • 545
  • 2
  • 9
  • 23

1 Answers1

0

You can simply evaluate if the BUILD_NUMBER is even or odd and pick the agent accordingly in your pipeline:

if(BUILD_NUMBER.toInteger() % 2 == 0) {
    agentLabel = 'agent2' //Even
} else {
    agentLabel = 'agent1' //Odd
}

pipeline {
    agent {
        label agentLabel
    }
    stages {
        ...
    }
}
Dibakar Aditya
  • 3,893
  • 1
  • 14
  • 25