Resolution
Create a new Job Template.
Set Type to be "Groovy template for pipeline"
Create a General job definition template based on Template Groovy Transformer syntax that specifies the Polling Interval.
-
The easiest way to achieve this, is to create a regular pipeline job, configuring the polling interval
-
Copy the contents of
<flow definition="">
element from the generated config.xml. This can be accessed from the browser by navigating to<jobname>/config.xml
-
Replace with any required templating - eg if the Polling Interval is to be configurable per instance
-
Remove the
<definition>
element from the copied XML as this will be substituted in by the templating engine
Create a Flow Script
First ensure that the SCM step has polling enabled -
eg: git poll: true, url: 'https://github.com/harniman/hello-world-simple-mvn'
Example 1
Configure a 5 minute polling interval for all instances of a pipeline:
General job definition:
<flow-definition plugin="workflow-job@1.8"> <actions/> <description>A test pipeline</description> <keepDependencies>false</keepDependencies> <properties/> <triggers> <hudson.triggers.SCMTrigger> <spec>5 * * * *</spec> <ignorePostCommitHooks>false</ignorePostCommitHooks> </hudson.triggers.SCMTrigger> </triggers> </flow-definition>
Example 2
Allow per job instance configuration of the polling interval
Pipeline Attributes:
ID: interval
Type: Text-field
Help: Interval will be set as the required polling interval, i.e: "5 * * * *" in the job instance
General job definition:
<flow-definition plugin="workflow-job@1.8"> <actions/> <description>A test pipeline</description> <keepDependencies>false</keepDependencies> <properties/> <triggers> <hudson.triggers.SCMTrigger> <spec>${interval}</spec> <ignorePostCommitHooks>false</ignorePostCommitHooks> </hudson.triggers.SCMTrigger> </triggers> </flow-definition>