I’m working with Jenkins Pipeline, and I have a question regarding agent allocation for different stages in a pipeline. I have a scenario where I have multiple nodes with the same label, and I want to know whether Jenkins will try to use the same agent throughout the pipeline for the same job.
From my understanding, Jenkins will try to use the same agent for all stages of a pipeline when the agent is defined with a label. However, I’d like to find an official document or any supporting reference for this statement. Here’s my scenario:
I have three nodes with the same label:
- stateful-0
- stateful-1
- stateful-2
My Jenkinsfile has the following structure:
pipeline {
agent {
label ‘stateful’
}
stages {
stage(‘Stage 1’) {
steps {
// …
}
}
stage(‘Stage 2’) {
steps {
// …
}
}
stage(‘Stage 3’) {
steps {
// …
}
}
}
}
My question is: Will Jenkins try to use the same agent throughout the pipeline for the same job if the agent is defined with a label? For example, if Stage 1 is running on stateful-1, will Stage 2 and Stage 3 also run on stateful-1?
If possible, is there any official documentation or supporting references to help clarify this behavior.
Thank you!