diff --git a/jenkins_jobs/modules/triggers.py b/jenkins_jobs/modules/triggers.py index 46be24ad7..d66727e49 100644 --- a/jenkins_jobs/modules/triggers.py +++ b/jenkins_jobs/modules/triggers.py @@ -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: + + :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, diff --git a/tests/triggers/fixtures/pollscm001.xml b/tests/triggers/fixtures/pollscm001.xml index 90a45521a..1fb7b5dd5 100644 --- a/tests/triggers/fixtures/pollscm001.xml +++ b/tests/triggers/fixtures/pollscm001.xml @@ -3,6 +3,7 @@ */15 * * * * + false diff --git a/tests/triggers/fixtures/pollscm001.yaml b/tests/triggers/fixtures/pollscm001.yaml index d60153a22..2a21eaef6 100644 --- a/tests/triggers/fixtures/pollscm001.yaml +++ b/tests/triggers/fixtures/pollscm001.yaml @@ -1,2 +1,3 @@ triggers: - - pollscm: "*/15 * * * *" \ No newline at end of file + - pollscm: + cron: "*/15 * * * *" diff --git a/tests/triggers/fixtures/pollscm002.xml b/tests/triggers/fixtures/pollscm002.xml new file mode 100644 index 000000000..cd0aa6daa --- /dev/null +++ b/tests/triggers/fixtures/pollscm002.xml @@ -0,0 +1,9 @@ + + + + + */30 * * * * + true + + + diff --git a/tests/triggers/fixtures/pollscm002.yaml b/tests/triggers/fixtures/pollscm002.yaml new file mode 100644 index 000000000..a4a5b48ef --- /dev/null +++ b/tests/triggers/fixtures/pollscm002.yaml @@ -0,0 +1,4 @@ +triggers: + - pollscm: + cron: "*/30 * * * *" + ignore-post-commit-hooks: True diff --git a/tests/triggers/fixtures/pollscm003.xml b/tests/triggers/fixtures/pollscm003.xml new file mode 100644 index 000000000..c9eca9613 --- /dev/null +++ b/tests/triggers/fixtures/pollscm003.xml @@ -0,0 +1,9 @@ + + + + + */30 * * * * + false + + + diff --git a/tests/triggers/fixtures/pollscm003.yaml b/tests/triggers/fixtures/pollscm003.yaml new file mode 100644 index 000000000..77ce320bb --- /dev/null +++ b/tests/triggers/fixtures/pollscm003.yaml @@ -0,0 +1,3 @@ +# Deprecated usage, here to test backward compatibility +triggers: + - pollscm: "*/30 * * * *"