How to configure Jenkins Pipeline to run a SubVersion poll?

We have been using Jenkins for continuous integration for some time. A typical build task is set by the SVN repository and credentials in the Source Control section, then in the Build Triggers section we turn on Poll SCM with a polling schedule every 10 minutes (H / 10 * * * *). We updated to the last Jenkins version and hope to customize the piping assembly. A typical script pipeline looks like this:

node { stage 'Build' build job: 'MyApplication Build' stage 'Deploy to test environment' build job: 'MyApplication Deploy', parameters: [ [$class: 'StringParameterValue', name: 'DatabaseServer', value: 'DatabaseServer1'], [$class: 'StringParameterValue', name: 'WebServer', value: 'WebServer1'] ] stage 'RunIntegrationTests' build job: 'MyApplication Test', parameters: [ [$class: 'StringParameterValue', name: 'DatabaseServer', value: 'DatabaseServer1'], [$class: 'StringParameterValue', name: 'WebServer', value: 'WebServer1'] ] } 

When the pipeline job is started manually, everything works fine, however, we would like this pipeline to run every time a new revision is checked in the SVN repository. The pipeline configuration has the option to run “SCM polling”, but does not have a “Source Control” section, where you can specify your repository. How can we achieve this?

+11
source share
6 answers

The solution I found to work is:

  • Move the script pipeline to a file (the default is JenkinsFile) and save it in the root of my project in SubVersion.
  • Set the Pipeline script from SCM pipeline source definition source, enter information about where to find my project in SubVersion according to the normal Jenkins build job, and set the script path to point to the JenkinsFile containing the script pipeline.
  • Set the pipeline job assembly trigger to SCM Poll and enter a schedule.
  • Manually perform work with the conveyor

It seemed like step 4, manually completing the job on the pipeline, because of which the polling trigger picks up the correct repository for polling. Before that, he did not seem to know where to look.

+6
source

Using the Jenkins declarative pipeline script, you can configure the job to poll the 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 query all the SCM repository URLs associated with your assembly, including the URLs specified in the checkout steps, the declarative pipeline script URL from SCM, and the URL of your global pipeline libraries. If you really want the pipeline to run for each revision, you need to set the hook instead after commit .

+5
source

It seems to me that you need a Checkout stage before the Build stage, which consists of SCM information. This allows the SCM polling job at the desired interval to start the pipeline.

You can even use the Pipeline script without having pipeline codes to store like JenkinsFile in SCM.

Below is my SVN Checkout script code before the Build phase:

 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']]) } 

It works only for my work with the conveyor. Hope this helps.

+4
source

Alternatively, when the script pipeline is not part of the project or is not defined in the task, you can add poll: true at the verification 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 start, he will start polling with this SCM as well as from SCM, where is the pipeline, if so.

This parameter is documented in https://jenkins.io/doc/pipeline/steps/workflow-scm-step/#code-checkout-code-general-scm , at the very end of the page without details.

+1
source

So we had a lot of problems to get this to work. Here's how we solved the problem:

In Jenkins, you work on the assembly line . The only content required in this work:

  • POLL SCM (with some arbitrary value like @monthly )
  • Where should work find your Jenkinsfile

All other settings are included in the Jenkinsfile file . Anyway:

  triggers { pollSCM('@monthly')} 

Should still be specified in your Jenkinsfile, even if it is already specified in your work.

However, as zionyx said , you need to place an order before doing anything else. In our case, we wanted to avoid this for many reasons. Fortunately, this still works if you have: depthOption: 'empty' .

Finally, you need to manually start the first run of the job .

We made a small function that you can 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]])} 
+1
source

data

  • Jenkins Pipeline does not have the ability to be run from SCM.
  • Jenkins Work has the ability to be Initiated from SCM.

=> The easiest way to achieve this:

  1. Create a Jenkins job that runs from SCM.
  2. Configure the Jenkin pipeline that will run after the Jenkins Job project is built.

It!

-one
source

All Articles