Consider the following setup using Jenkins 2.176.1:
- A new pipeline project named
Foobar Poll SCMas (only) build trigger, with:H/5 * * * *... under the assumption that this refers to the SCM configured in the next stepPipeline script from SCMwith SCMGitand a working Git repository URL- Uncheck
Lightweight checkoutbecause of JENKINS-42971 and JENKINS-48431 (I am using build variables in the real project andJenkinsfile; also this may affect howpollSCMworks, so I include this step here)
- Uncheck
- Said repository contains a simple
Jenkinsfile
The Jenkinsfile looks approximately like this:
#!groovy
pipeline {
agent any
triggers { pollSCM 'H/5 * * * *' }
stages {
stage('Source checkout') {
steps {
checkout(
[
$class: 'GitSCM',
branches: [],
browser: [],
doGenerateSubmoduleConfigurations: false,
extensions: [],
submoduleCfg: [],
userRemoteConfigs: [
[
url: 'git://server/project.git'
]
]
]
)
stash 'source'
}
}
stage('OS-specific binaries') {
parallel {
stage('Linux') {
agent { label 'gcc && linux' }
steps {
unstash 'source'
echo 'Pretending to do a build here'
}
}
stage('Windows') {
agent { label 'windows' }
steps {
unstash 'source'
echo 'Pretending to do a build here'
}
}
}
}
}
}
My understanding so far was that:
- a change to the
Jenkinsfile(not the whole repo) triggers the pipeline on any registered agent (or as configured in the pipeline project). - said agent (which is random) uses the
pollSCMtrigger in theJenkinsfileto trigger the pipeline stages.- But where does the
pollSCMtrigger poll (what SCM repo)? And if it's a random agent then how can it reasonably detect changes across poll runs?
- But where does the
- then the stages are being executed on the agents as allocated ...
Now I am confused what refers to what. So here my questions (all interrelated which is why I keep it together in one question):
- The pipeline project polls the SCM just for the
Jenkinsfileor for any changes? The repository in my case is the same (forJenkinsfileand source files to build binaries from).- If the (project-level) polling triggers at any change rather than changes to the Jenkinsfile
- Does the
pollSCMtrigger in theJenkinsfilesomehow automagically refer to thecheckoutstep?- Then ... what would happen, would I have multiple
checkoutsteps with differing settings? - What determines what repository (and what contents inside of that) gets polled?
- Then ... what would happen, would I have multiple
- ... or is this akin to the
checkout scmshorthand andpollSCMactually refers to the SCM configured in the pipeline project and so I can shorten thecheckout()tocheckout scmin thesteps?
Unfortunately the user handbook didn't answer any of those questions and pollSCM has a total of four occurrences on a single page within the entire handbook.