pipeline {
agent any
stages {
stage ('Build') {
steps {
sh 'cat Jenkinsfile'
}
}
}
}
This pipeline fails:
pipeline {
agent any
stages {
stage ('Build') {
agent any
steps {
sh 'cat Jenkinsfile'
}
}
}
}
The reason this happens is that the agent inside a stage step does not do checkout scm automatically. This is very confusing behavior. Agent initialization should be consistent whether at top or inside a stage.
pipeline { agent any stages { stage ('Build') { steps { sh 'cat Jenkinsfile' } } } }
{code}
This pipeline fails:
{code:language=groovy}
pipeline { agent any stages { stage ('Build') { agent any steps { sh 'cat Jenkinsfile' } } } }
{code}
The reason this happens is that the agent inside a stage step does not do checkout scm automatically. This is very confusing behavior. Agent initialization should be consistent whether at top or inside a stage.
I would expect to do something like this to make an agent in a stage not do checkout: {code:language=groovy} pipeline { agent any options { skipDefaultCheckout()
The reasoning behind automatic checkout only happening at the top level was a conscious decision - and frankly, one I'd still advocate for. But it may make sense to have a per-stage option for "do a fresh checkout of SCM in this stage" - independent of the agent configuration. There've been some other things that have come up that may make sense as part of a stage-level options section.
So what I'm leaning towards right now is hooking logic so that the label Declarative agent does always do a checkout (assuming skipDefaultCheckout isn't specified at the top-level, that is) - that'll still avoid doing a redundant checkout when docker or dockerfile are used for an individual stage and reuseNode is specified, since we never actually go through the label Declarative agent then. Implementing now on top of https://github.com/jenkinsci/pipeline-model-definition-plugin/pull/109, which is in the same code (that's JENKINS-41900).