From 673927e5e9d8adea47d6efe525ef5dda2668ef81 Mon Sep 17 00:00:00 2001 From: Kien Ha Date: Mon, 25 Jul 2016 15:09:21 -0400 Subject: [PATCH] Update Delivery Pipeline plugin to use convert xml - Add plugin="delivery-pipeline-plugin" attribute - Rename test files to be more descriptive Change-Id: I9db5315e425da6bd5c69b533c79d6d5ab4ed1e70 Signed-off-by: Kien Ha --- jenkins_jobs/modules/properties.py | 27 ++++++++++++------- jenkins_jobs/modules/wrappers.py | 27 ++++++++++++------- ...peline1.xml => delivery-pipeline-full.xml} | 2 +- ...line1.yaml => delivery-pipeline-full.yaml} | 0 ...ine2.xml => delivery-pipeline-minimal.xml} | 2 +- ...e2.yaml => delivery-pipeline-minimal.yaml} | 0 ...peline1.xml => delivery-pipeline-full.xml} | 2 +- ...line1.yaml => delivery-pipeline-full.yaml} | 0 ...ine2.xml => delivery-pipeline-minimal.xml} | 2 +- ...e2.yaml => delivery-pipeline-minimal.yaml} | 0 10 files changed, 40 insertions(+), 22 deletions(-) rename tests/properties/fixtures/{delivery-pipeline1.xml => delivery-pipeline-full.xml} (76%) rename tests/properties/fixtures/{delivery-pipeline1.yaml => delivery-pipeline-full.yaml} (100%) rename tests/properties/fixtures/{delivery-pipeline2.xml => delivery-pipeline-minimal.xml} (71%) rename tests/properties/fixtures/{delivery-pipeline2.yaml => delivery-pipeline-minimal.yaml} (100%) rename tests/wrappers/fixtures/{delivery-pipeline1.xml => delivery-pipeline-full.xml} (74%) rename tests/wrappers/fixtures/{delivery-pipeline1.yaml => delivery-pipeline-full.yaml} (100%) rename tests/wrappers/fixtures/{delivery-pipeline2.xml => delivery-pipeline-minimal.xml} (71%) rename tests/wrappers/fixtures/{delivery-pipeline2.yaml => delivery-pipeline-minimal.yaml} (100%) diff --git a/jenkins_jobs/modules/properties.py b/jenkins_jobs/modules/properties.py index 96685a5e4..31c2831cf 100644 --- a/jenkins_jobs/modules/properties.py +++ b/jenkins_jobs/modules/properties.py @@ -39,6 +39,7 @@ from jenkins_jobs.errors import InvalidAttributeError from jenkins_jobs.errors import JenkinsJobsException from jenkins_jobs.errors import MissingAttributeError import jenkins_jobs.modules.base +from jenkins_jobs.modules.helpers import convert_mapping_to_xml def builds_chain_fingerprinter(parser, xml_parent, data): @@ -632,20 +633,28 @@ def delivery_pipeline(parser, xml_parent, data): :arg str description: task description template for this job (default '') - Example: + Minimal Example: .. literalinclude:: - /../../tests/properties/fixtures/delivery-pipeline1.yaml + /../../tests/properties/fixtures/delivery-pipeline-minimal.yaml :language: yaml + Full Example: + + .. literalinclude:: + /../../tests/properties/fixtures/delivery-pipeline-full.yaml + :language: yaml """ - pipeline = XML.SubElement(xml_parent, - 'se.diabol.jenkins.pipeline.' - 'PipelineProperty') - XML.SubElement(pipeline, 'stageName').text = data.get('stage', '') - XML.SubElement(pipeline, 'taskName').text = data.get('task', '') - XML.SubElement(pipeline, 'descriptionTemplate').text = str( - data.get('description', '')) + pipeline = XML.SubElement( + xml_parent, 'se.diabol.jenkins.pipeline.PipelineProperty') + pipeline.set('plugin', 'delivery-pipeline-plugin') + + mapping = [ + ('stage', 'stageName', ''), + ('task', 'taskName', ''), + ('description', 'descriptionTemplate', ''), + ] + convert_mapping_to_xml(pipeline, data, mapping, fail_required=True) def zeromq_event(parser, xml_parent, data): diff --git a/jenkins_jobs/modules/wrappers.py b/jenkins_jobs/modules/wrappers.py index 53e475053..38fdb0830 100644 --- a/jenkins_jobs/modules/wrappers.py +++ b/jenkins_jobs/modules/wrappers.py @@ -1521,18 +1521,27 @@ def delivery_pipeline(parser, xml_parent, data): :arg bool set-display-name: Set the generated version as the display name for the build (default false) - Example: + Minimal Example: - .. literalinclude:: /../../tests/wrappers/fixtures/delivery-pipeline1.yaml + .. literalinclude:: + /../../tests/wrappers/fixtures/delivery-pipeline-minimal.yaml + :language: yaml + Full Example: + + .. literalinclude:: + /../../tests/wrappers/fixtures/delivery-pipeline-full.yaml + :language: yaml """ - pvc = XML.SubElement(xml_parent, - 'se.diabol.jenkins.pipeline.' - 'PipelineVersionContributor') - XML.SubElement(pvc, 'versionTemplate').text = data.get( - 'version-template', '') - XML.SubElement(pvc, 'updateDisplayName').text = str(data.get( - 'set-display-name', False)).lower() + pvc = XML.SubElement( + xml_parent, 'se.diabol.jenkins.pipeline.PipelineVersionContributor') + pvc.set('plugin', 'delivery-pipeline-plugin') + + mapping = [ + ('version-template', 'versionTemplate', ''), + ('set-display-name', 'updateDisplayName', False), + ] + convert_mapping_to_xml(pvc, data, mapping, fail_required=True) def matrix_tie_parent(parser, xml_parent, data): diff --git a/tests/properties/fixtures/delivery-pipeline1.xml b/tests/properties/fixtures/delivery-pipeline-full.xml similarity index 76% rename from tests/properties/fixtures/delivery-pipeline1.xml rename to tests/properties/fixtures/delivery-pipeline-full.xml index c62e23f90..132764e3f 100644 --- a/tests/properties/fixtures/delivery-pipeline1.xml +++ b/tests/properties/fixtures/delivery-pipeline-full.xml @@ -1,7 +1,7 @@ - + Stage Task Task-Description diff --git a/tests/properties/fixtures/delivery-pipeline1.yaml b/tests/properties/fixtures/delivery-pipeline-full.yaml similarity index 100% rename from tests/properties/fixtures/delivery-pipeline1.yaml rename to tests/properties/fixtures/delivery-pipeline-full.yaml diff --git a/tests/properties/fixtures/delivery-pipeline2.xml b/tests/properties/fixtures/delivery-pipeline-minimal.xml similarity index 71% rename from tests/properties/fixtures/delivery-pipeline2.xml rename to tests/properties/fixtures/delivery-pipeline-minimal.xml index f34569ff2..db61340d5 100644 --- a/tests/properties/fixtures/delivery-pipeline2.xml +++ b/tests/properties/fixtures/delivery-pipeline-minimal.xml @@ -1,7 +1,7 @@ - + diff --git a/tests/properties/fixtures/delivery-pipeline2.yaml b/tests/properties/fixtures/delivery-pipeline-minimal.yaml similarity index 100% rename from tests/properties/fixtures/delivery-pipeline2.yaml rename to tests/properties/fixtures/delivery-pipeline-minimal.yaml diff --git a/tests/wrappers/fixtures/delivery-pipeline1.xml b/tests/wrappers/fixtures/delivery-pipeline-full.xml similarity index 74% rename from tests/wrappers/fixtures/delivery-pipeline1.xml rename to tests/wrappers/fixtures/delivery-pipeline-full.xml index 5afab7117..84fa9f227 100644 --- a/tests/wrappers/fixtures/delivery-pipeline1.xml +++ b/tests/wrappers/fixtures/delivery-pipeline-full.xml @@ -1,7 +1,7 @@ - + 1.0.0-${BUILD_NUMBER} true diff --git a/tests/wrappers/fixtures/delivery-pipeline1.yaml b/tests/wrappers/fixtures/delivery-pipeline-full.yaml similarity index 100% rename from tests/wrappers/fixtures/delivery-pipeline1.yaml rename to tests/wrappers/fixtures/delivery-pipeline-full.yaml diff --git a/tests/wrappers/fixtures/delivery-pipeline2.xml b/tests/wrappers/fixtures/delivery-pipeline-minimal.xml similarity index 71% rename from tests/wrappers/fixtures/delivery-pipeline2.xml rename to tests/wrappers/fixtures/delivery-pipeline-minimal.xml index 8bc3c0dfd..5f5456343 100644 --- a/tests/wrappers/fixtures/delivery-pipeline2.xml +++ b/tests/wrappers/fixtures/delivery-pipeline-minimal.xml @@ -1,7 +1,7 @@ - + false diff --git a/tests/wrappers/fixtures/delivery-pipeline2.yaml b/tests/wrappers/fixtures/delivery-pipeline-minimal.yaml similarity index 100% rename from tests/wrappers/fixtures/delivery-pipeline2.yaml rename to tests/wrappers/fixtures/delivery-pipeline-minimal.yaml