diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py index 90e968fd4..c2fd14f98 100644 --- a/jenkins_jobs/modules/publishers.py +++ b/jenkins_jobs/modules/publishers.py @@ -4121,6 +4121,56 @@ def downstream_ext(parser, xml_parent, data): data.get('only-on-local-scm-change', False)).lower() +def rundeck(parser, xml_parent, data): + """yaml: rundeck + Trigger a rundeck job when the build is complete. + + Requires the Jenkins :jenkins-wiki:`RunDeck + Plugin `. + + :arg str job-id: The RunDeck job identifier. (required) + This could be: + * ID example : "42" + * UUID example : "2027ce89-7924-4ecf-a963-30090ada834f" + * reference, in the format : "project:group/job" + :arg str options: List of options for the Rundeck job, in Java-Properties + format: key=value (default "") + :arg str node-filters: List of filters to optionally filter the nodes + included by the job. (default "") + :arg str tag: Used for on-demand job scheduling on rundeck: if a tag is + specified, the job will only execute if the given tag is present in the + SCM changelog. (default "") + :arg bool wait-for-rundeck: If true Jenkins will wait for the job to + complete, if false the job will be started and Jenkins will move on. + (default false) + :arg bool fail-the-build: If true a RunDeck job failure will cause the + Jenkins build to fail. (default false) + + Example: + + .. literalinclude:: /../../tests/publishers/fixtures/rundeck001.yaml + :language: yaml + + Full example: + + .. literalinclude:: /../../tests/publishers/fixtures/rundeck002.yaml + :language: yaml + """ + + p = XML.SubElement( + xml_parent, + 'org.jenkinsci.plugins.rundeck.RundeckNotifier') + + XML.SubElement(p, 'jobId').text = str(data.get('job-id')) + XML.SubElement(p, 'options').text = str(data.get('options', '')) + XML.SubElement(p, 'nodeFilters').text = str(data.get('node-filters', '')) + XML.SubElement(p, 'tag').text = str(data.get('tag', '')) + XML.SubElement(p, 'shouldWaitForRundeckJob').text = str( + data.get('wait-for-rundeck', False)).lower() + XML.SubElement(p, 'shouldFailTheBuild').text = str( + data.get('fail-the-build', False)).lower() + + def create_publishers(parser, action): dummy_parent = XML.Element("dummy") parser.registry.dispatch('publisher', parser, dummy_parent, action) diff --git a/setup.cfg b/setup.cfg index 37ec916fc..22616829c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -192,6 +192,7 @@ jenkins_jobs.publishers = rich-text-publisher=jenkins_jobs.modules.publishers:rich_text_publisher robot=jenkins_jobs.modules.publishers:robot ruby-metrics=jenkins_jobs.modules.publishers:ruby_metrics + rundeck=jenkins_jobs.modules.publishers:rundeck s3=jenkins_jobs.modules.publishers:s3 scan-build=jenkins_jobs.modules.publishers:scan_build scoverage=jenkins_jobs.modules.publishers:scoverage diff --git a/tests/publishers/fixtures/rundeck001.xml b/tests/publishers/fixtures/rundeck001.xml new file mode 100644 index 000000000..1f72aceed --- /dev/null +++ b/tests/publishers/fixtures/rundeck001.xml @@ -0,0 +1,13 @@ + + + + + testproject:group/jobname + + + + false + false + + + diff --git a/tests/publishers/fixtures/rundeck001.yaml b/tests/publishers/fixtures/rundeck001.yaml new file mode 100644 index 000000000..1eb8ab767 --- /dev/null +++ b/tests/publishers/fixtures/rundeck001.yaml @@ -0,0 +1,3 @@ +publishers: + - rundeck: + job-id: testproject:group/jobname diff --git a/tests/publishers/fixtures/rundeck002.xml b/tests/publishers/fixtures/rundeck002.xml new file mode 100644 index 000000000..5240ebc5d --- /dev/null +++ b/tests/publishers/fixtures/rundeck002.xml @@ -0,0 +1,15 @@ + + + + + testproject:group/jobname + STUFF_FOR_THE_JOB=stuff +ANOTHER_VAR=more_stuff + + dev + master + true + true + + + diff --git a/tests/publishers/fixtures/rundeck002.yaml b/tests/publishers/fixtures/rundeck002.yaml new file mode 100644 index 000000000..ee35646f3 --- /dev/null +++ b/tests/publishers/fixtures/rundeck002.yaml @@ -0,0 +1,10 @@ +publishers: + - rundeck: + job-id: testproject:group/jobname + options: | + STUFF_FOR_THE_JOB=stuff + ANOTHER_VAR=more_stuff + node-filters: dev + tag: master + wait-for-rundeck: true + fail-the-build: true