Issue
I'm trying to run a jenkins file with multiple agents in it, but I'm running into errors. Here's a snippet of my jenkins file:
pipeline {
agent {
docker {
label 'agentAAA'
...
}
node {
label 'agentBBB'
...
}
}
...
stages {
stage('to run on AAA') {
agent {
label 'agentAAA'
}
...
}
stage('to run on BBB') {
agent {
label 'agentBBB'
}
...
}
stage('to run on BBB') {
agent {
label 'agentBBB'
}
...
}
I'm getting these errors:
- Only one agent type is allowed per agent section
- No agent type specified. Must be one of [any, docker, dockerfile, label, none]
I can't find any examples in the documentation of how to refer to a previously declared agent. I see how to declare the agent in each individual stage, but I'd end up with many repeated declarations in my file.
Solution
You need to specify agent as none for overall pipeline, then you can specify agent for each stage explicitly as shown in below example. Populate the details as and what required.
pipeline {
agent none
stages {
stage ('Stage-1') {
agent { label 'agent-1' }
steps {
script {
}
}
}
stage ('Stage-2') {
agent { label 'agent-2' }
steps {
script {
}
}
}
}
}
Refer link for further details - https://jenkins.io/doc/book/pipeline/jenkinsfile/#using-multiple-agents
Answered By - Mishi.Srivastava
Answer Checked By - Gilberto Lyons (JavaFixing Admin)