We have been using Jenkins for Continuous Integration for some time. A typical build job specifies the SVN repository and credentials in the \"Source Code Management\" secti
So, we had A LOT of problems getting this to work. Here is how we solved the problem:
In Jenkins you make a Pipeline Job. The only contents that are required in this job are:
@monthly
)Every other setting goes into the Jenkinsfile. However:
triggers {
pollSCM('@monthly')}
Should STILL be specified in your Jenkinsfile even though it is already specified in your job.
However, as zionyx said you need to checkout before you do anything else. In our case we wanted to avoid this for many reasons. Luckily it still works if you have:
depthOption: 'empty'
.
Finally, you need to manually start the first job run.
We made a little function that you can perhaps use:
def checkoutSVN(Boolean ignoreExternalsOption, String local, String remote, String updater) {
checkout([$class: 'SubversionSCM',
additionalCredentials:
[[credentialsId: 'get-this-from-your-jenkins',
realm: '<https://your-server> CollabNet Subversion Repository']],
excludedCommitMessages: '',
excludedRegions: '',
excludedRevprop: '',
excludedUsers: '',
filterChangelog: false,
ignoreDirPropChanges: false,
includedRegions: '',
locations: [[credentialsId: 'get-this-from-your-jenkins',
depthOption: 'empty',
ignoreExternalsOption: ignoreExternalsOption,
local: local,
remote: remote]],
quietOperation: false,
workspaceUpdater: [$class: updater]])}
Facts
=> The simplest way to achieve this is:
That's it!
I think you need a Checkout stage before before your Build stage, which consists of the SCM information. This allows the job to Poll SCM at the desired interval and run the pipeline.
You can even use Pipeline script, without having the pipeline codes to store as a JenkinsFile in SCM.
Below is my SVN Checkout stage pipeline code before my Build stage:
stage('Checkout') {
checkout([$class: 'SubversionSCM',
additionalCredentials: [],
excludedCommitMessages: '',
excludedRegions: '',
excludedRevprop: '',
excludedUsers: 'buildbot',
filterChangelog: false,
ignoreDirPropChanges: false,
includedRegions: '',
locations: [[credentialsId: 'b86bc2b6-994b-4811-ac98-0f35e9a9b114',
depthOption: 'infinity',
ignoreExternalsOption: true,
local: '.',
remote: "http://svn/something/trunk/"]],
workspaceUpdater: [$class: 'UpdateUpdater']])
}
Works for my pipeline job though. Hope this helps.
As an alternative to when the pipeline script is not part of the project or is defined in the job, you can add poll: true
to your checkout stage.
Example:
stage('checkout') {
checkout(
changelog: true,
poll: true, /*This is the important option*/
scm: [
$class: 'SubversionSCM',
filterChangelog: false,
ignoreDirPropChanges: false,
locations: [...], /*ommited for obvious reasons*/
workspaceUpdater: [$class: 'CheckoutUpdater']
])
}
After the first run it will start polling from this SCM also as from the SCM where the pipeline is if it is the case.
This option is documented at https://jenkins.io/doc/pipeline/steps/workflow-scm-step/#code-checkout-code-general-scm , in the very end of the page without details.
Using a Jenkins Declarative Pipeline script, you can configure a job to poll an SVN repository URL every 10 minutes as follows:
pipeline {
agent any
triggers {
pollSCM 'H/10 * * * *'
}
stages {
stage('checkout') {
steps {
checkout([
$class: 'SubversionSCM',
additionalCredentials: [],
excludedCommitMessages: '',
excludedRegions: '',
excludedRevprop: '',
excludedUsers: '',
filterChangelog: false,
ignoreDirPropChanges: false,
includedRegions: '',
locations: [[
credentialsId: 'mySvnCredentials',
depthOption: 'infinity',
ignoreExternalsOption: true,
local: '.',
remote: 'http://example.com/svn/url/trunk']],
workspaceUpdater: [$class: 'CheckoutUpdater']
])
}
}
}
}
The pollSCM
trigger should automatically poll all SCM Repository URLs associated with your build, including URLs specified by checkout
steps, the URL of your Declarative Pipeline script from SCM, and the URL of your Global Pipeline Libraries. If you truly want the pipeline to be run for every single revision however, you'll need to set up a post-commit hook instead.
The solution that I have found to work is:
It seemed to be step 4, manually running the pipeline job that caused the poll trigger to pick up the correct repository to poll. Before that it didn't seem to know where to look.