Customized pollscm trigger

Changed the pollscm trigger in order to grant the possibility
to modify the value of ignorePostCommitHooks attribute
Backward compatible is kept and warnings are logged

Change-Id: I8347912ccfa9faf77610f4594f0b69b017e0d825
This commit is contained in:
Nicolas Glayre 2015-08-12 13:50:03 +02:00
parent 347a231e07
commit 57d485e2a1
7 changed files with 61 additions and 5 deletions

View File

@ -35,7 +35,8 @@ import xml.etree.ElementTree as XML
import jenkins_jobs.modules.base
from jenkins_jobs.modules import hudson_model
from jenkins_jobs.errors import (InvalidAttributeError,
JenkinsJobsException)
JenkinsJobsException,
MissingAttributeError)
import logging
import re
try:
@ -565,16 +566,44 @@ def pollscm(parser, xml_parent, data):
"""yaml: pollscm
Poll the SCM to determine if there has been a change.
:arg string pollscm: the polling interval (cron syntax)
:Parameter: the polling interval (cron syntax)
.. deprecated:: 1.3.0. Please use :ref:`cron <cron>`.
.. _cron:
:arg string cron: the polling interval (cron syntax, required)
:arg bool ignore-post-commit-hooks: Ignore changes notified by SCM
post-commit hooks. The subversion-plugin supports this since
version 1.44. (default false)
Example:
.. literalinclude:: /../../tests/triggers/fixtures/pollscm001.yaml
.. literalinclude:: /../../tests/triggers/fixtures/pollscm002.yaml
:language: yaml
"""
try:
cron = data['cron']
ipch = str(data.get('ignore-post-commit-hooks', False)).lower()
except KeyError as e:
# ensure specific error on the attribute not being set is raised
# for new format
raise MissingAttributeError(e)
except TypeError:
# To keep backward compatibility
logger.warn("Your pollscm usage is deprecated, please use"
" the syntax described in the documentation"
" instead")
cron = data
ipch = 'false'
if not cron:
raise InvalidAttributeError('cron', cron)
scmtrig = XML.SubElement(xml_parent, 'hudson.triggers.SCMTrigger')
XML.SubElement(scmtrig, 'spec').text = data
XML.SubElement(scmtrig, 'spec').text = cron
XML.SubElement(scmtrig, 'ignorePostCommitHooks').text = ipch
def build_pollurl_content_type(xml_parent, entries, prefix,

View File

@ -3,6 +3,7 @@
<triggers class="vector">
<hudson.triggers.SCMTrigger>
<spec>*/15 * * * *</spec>
<ignorePostCommitHooks>false</ignorePostCommitHooks>
</hudson.triggers.SCMTrigger>
</triggers>
</project>

View File

@ -1,2 +1,3 @@
triggers:
- pollscm: "*/15 * * * *"
- pollscm:
cron: "*/15 * * * *"

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<triggers class="vector">
<hudson.triggers.SCMTrigger>
<spec>*/30 * * * *</spec>
<ignorePostCommitHooks>true</ignorePostCommitHooks>
</hudson.triggers.SCMTrigger>
</triggers>
</project>

View File

@ -0,0 +1,4 @@
triggers:
- pollscm:
cron: "*/30 * * * *"
ignore-post-commit-hooks: True

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<triggers class="vector">
<hudson.triggers.SCMTrigger>
<spec>*/30 * * * *</spec>
<ignorePostCommitHooks>false</ignorePostCommitHooks>
</hudson.triggers.SCMTrigger>
</triggers>
</project>

View File

@ -0,0 +1,3 @@
# Deprecated usage, here to test backward compatibility
triggers:
- pollscm: "*/30 * * * *"