diff --git a/jenkins_jobs/modules/triggers.py b/jenkins_jobs/modules/triggers.py index fcdf145fd..e8c317996 100644 --- a/jenkins_jobs/modules/triggers.py +++ b/jenkins_jobs/modules/triggers.py @@ -1700,6 +1700,36 @@ def rabbitmq(registry, xml_parent, data): raise MissingAttributeError(e.arg[0]) +def parameterized_timer(parser, xml_parent, data): + """yaml: parameterized-timer + Trigger builds with parameters at certain times. + Requires the Jenkins :jenkins-wiki:`Parameterized Scheduler Plugin + `. + + :arg str cron: cron syntax of when to run and with which parameters + (required) + + Example: + + .. literalinclude:: + /../../tests/triggers/fixtures/parameterized-timer001.yaml + :language: yaml + """ + + param_timer = XML.SubElement( + xml_parent, + 'org.jenkinsci.plugins.parameterizedscheduler.' + 'ParameterizedTimerTrigger') + + XML.SubElement(param_timer, 'spec').text = '' + + try: + XML.SubElement(param_timer, 'parameterizedSpecification').text = str( + data.get('cron')) + except KeyError as e: + raise MissingAttributeError(e) + + class Triggers(jenkins_jobs.modules.base.Base): sequence = 50 diff --git a/tests/triggers/fixtures/parameterized-timer001.xml b/tests/triggers/fixtures/parameterized-timer001.xml new file mode 100644 index 000000000..d05e44117 --- /dev/null +++ b/tests/triggers/fixtures/parameterized-timer001.xml @@ -0,0 +1,9 @@ + + + + + + @midnight % PARAM=value + + + diff --git a/tests/triggers/fixtures/parameterized-timer001.yaml b/tests/triggers/fixtures/parameterized-timer001.yaml new file mode 100644 index 000000000..93052ac85 --- /dev/null +++ b/tests/triggers/fixtures/parameterized-timer001.yaml @@ -0,0 +1,3 @@ +triggers: + - parameterized-timer: + cron: "@midnight % PARAM=value" diff --git a/tests/triggers/fixtures/parameterized-timer002.xml b/tests/triggers/fixtures/parameterized-timer002.xml new file mode 100644 index 000000000..ba3b47905 --- /dev/null +++ b/tests/triggers/fixtures/parameterized-timer002.xml @@ -0,0 +1,11 @@ + + + + + + 0 * * * * % param1=value1;param2=value2 +30 * * * * % param1=value3;param2=value4 + + + + diff --git a/tests/triggers/fixtures/parameterized-timer002.yaml b/tests/triggers/fixtures/parameterized-timer002.yaml new file mode 100644 index 000000000..a154b1115 --- /dev/null +++ b/tests/triggers/fixtures/parameterized-timer002.yaml @@ -0,0 +1,5 @@ +triggers: + - parameterized-timer: + cron: | + 0 * * * * % param1=value1;param2=value2 + 30 * * * * % param1=value3;param2=value4