diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py index c86cc41c4..080fa9ab2 100644 --- a/jenkins_jobs/modules/publishers.py +++ b/jenkins_jobs/modules/publishers.py @@ -31,7 +31,7 @@ import jenkins_jobs.modules.base from jenkins_jobs.modules import hudson_model from jenkins_jobs.modules.helpers import build_trends_publisher from jenkins_jobs.modules.helpers import findbugs_settings -from jenkins_jobs.errors import JenkinsJobsException +from jenkins_jobs.errors import JenkinsJobsException, InvalidAttributeError import logging import pkg_resources import sys @@ -4329,6 +4329,80 @@ def logstash(parser, xml_parent, data): data.get('fail-build', False)) +def image_gallery(parser, xml_parent, data): + """yaml: image-gallery + Produce an image gallery using Javascript library. Requires the Jenkins + :jenkins-wiki:`Image Gallery Plugin`. + + :arg str gallery-type: + + :gallery-type values: + * **archived-images-gallery** (default) + * **in-folder-comparative-gallery** + * **multiple-folder-comparative-gallery** + :arg str title: gallery title (optional) + :arg int image-width: width of the image (optional) + :arg bool unstable-if-no-artifacts: mark build as unstable + if no archived artifacts were found (default False) + :arg str includes: include pattern (valid for archived-images-gallery + gallery) + :arg str base-root-folder: base root dir (valid for comparative gallery) + :arg int image-inner-width: width of the image displayed in the inner + gallery popup (valid for comparative gallery, optional) + + Example: + + .. literalinclude:: /../../tests/publishers/fixtures/image-gallery001.yaml + + """ + def include_comparative_elements(gallery_parent_elem, gallery): + XML.SubElement(gallery_parent_elem, 'baseRootFolder').text = str( + gallery.get('base-root-folder', '')) + image_inner_width = gallery.get('image-inner-width', '') + if image_inner_width: + XML.SubElement(gallery_parent_elem, 'imageInnerWidth').text = str( + image_inner_width) + + package_prefix = 'org.jenkinsci.plugins.imagegallery.' + builder = XML.SubElement( + xml_parent, package_prefix + 'ImageGalleryRecorder' + ) + image_galleries = XML.SubElement(builder, 'imageGalleries') + galleries = { + 'archived-images-gallery': package_prefix + 'imagegallery.' + 'ArchivedImagesGallery', + 'in-folder-comparative-gallery': package_prefix + 'comparative.' + 'InFolderComparativeArchivedImagesGallery', + 'multiple-folder-comparative-gallery': package_prefix + 'comparative.' + 'MultipleFolderComparativeArchivedImagesGallery' + } + for gallery_def in data: + gallery_type = gallery_def.get('gallery-type', + 'archived-images-gallery') + if gallery_type not in galleries: + raise InvalidAttributeError('gallery-type', gallery_type, + galleries.keys()) + gallery_config = XML.SubElement( + image_galleries, galleries[gallery_type]) + XML.SubElement(gallery_config, 'title').text = str( + gallery_def.get('title', '')) + image_width = str(gallery_def.get('image-width', '')) + if image_width: + XML.SubElement(gallery_config, 'imageWidth').text = str( + image_width) + XML.SubElement( + gallery_config, + 'markBuildAsUnstableIfNoArchivesFound').text = str(gallery_def.get( + 'unstable-if-no-artifacts', False)) + if gallery_type == 'archived-images-gallery': + XML.SubElement(gallery_config, 'includes').text = str( + gallery_def.get('includes', '')) + if gallery_type == 'in-folder-comparative-gallery': + include_comparative_elements(gallery_config, gallery_def) + if gallery_type == 'multiple-folder-comparative-gallery': + include_comparative_elements(gallery_config, gallery_def) + + class Publishers(jenkins_jobs.modules.base.Base): sequence = 70 diff --git a/setup.cfg b/setup.cfg index caba307a5..f4cb40d55 100644 --- a/setup.cfg +++ b/setup.cfg @@ -161,6 +161,7 @@ jenkins_jobs.publishers = github-notifier=jenkins_jobs.modules.publishers:github_notifier groovy-postbuild=jenkins_jobs.modules.publishers:groovy_postbuild html-publisher=jenkins_jobs.modules.publishers:html_publisher + image-gallery=jenkins_jobs.modules.publishers:image_gallery ircbot=jenkins_jobs.modules.publishers:ircbot jabber=jenkins_jobs.modules.publishers:jabber jacoco=jenkins_jobs.modules.publishers:jacoco diff --git a/tests/publishers/fixtures/image-gallery001.xml b/tests/publishers/fixtures/image-gallery001.xml new file mode 100644 index 000000000..5a414609e --- /dev/null +++ b/tests/publishers/fixtures/image-gallery001.xml @@ -0,0 +1,29 @@ + + + + + + + Gallery 1 + 100 + True + path/images + + + Gallery 2 + 321 + False + path/images2 + 111 + + + Gallery 3 + 222 + False + path/images3 + 1 + + + + + diff --git a/tests/publishers/fixtures/image-gallery001.yaml b/tests/publishers/fixtures/image-gallery001.yaml new file mode 100644 index 000000000..8e0765b18 --- /dev/null +++ b/tests/publishers/fixtures/image-gallery001.yaml @@ -0,0 +1,18 @@ +publishers: + - image-gallery: + - gallery-type: archived-images-gallery + title: Gallery 1 + includes: path/images + image-width: 100 + unstable-if-no-artifacts: true + - gallery-type: in-folder-comparative-gallery + title: Gallery 2 + base-root-folder: path/images2 + image-width: 321 + image-inner-width: 111 + unstable-if-no-artifacts: false + - gallery-type: multiple-folder-comparative-gallery + title: Gallery 3 + base-root-folder: path/images3 + image-width: 222 + image-inner-width: 1 diff --git a/tests/publishers/fixtures/image-gallery002.xml b/tests/publishers/fixtures/image-gallery002.xml new file mode 100644 index 000000000..db8b13ef5 --- /dev/null +++ b/tests/publishers/fixtures/image-gallery002.xml @@ -0,0 +1,44 @@ + + + + + + + Gallery 1 + 100 + True + path/images + + + + <markBuildAsUnstableIfNoArchivesFound>False</markBuildAsUnstableIfNoArchivesFound> + <includes/> + </org.jenkinsci.plugins.imagegallery.imagegallery.ArchivedImagesGallery> + <org.jenkinsci.plugins.imagegallery.comparative.InFolderComparativeArchivedImagesGallery> + <title>Gallery 3 + 321 + True + path/images3 + 111 + + + + <markBuildAsUnstableIfNoArchivesFound>False</markBuildAsUnstableIfNoArchivesFound> + <baseRootFolder/> + </org.jenkinsci.plugins.imagegallery.comparative.InFolderComparativeArchivedImagesGallery> + <org.jenkinsci.plugins.imagegallery.comparative.MultipleFolderComparativeArchivedImagesGallery> + <title>Gallery 5 + 444 + True + path/images5 + 333 + + + + <markBuildAsUnstableIfNoArchivesFound>False</markBuildAsUnstableIfNoArchivesFound> + <baseRootFolder/> + </org.jenkinsci.plugins.imagegallery.comparative.MultipleFolderComparativeArchivedImagesGallery> + </imageGalleries> + </org.jenkinsci.plugins.imagegallery.ImageGalleryRecorder> + </publishers> +</project> diff --git a/tests/publishers/fixtures/image-gallery002.yaml b/tests/publishers/fixtures/image-gallery002.yaml new file mode 100644 index 000000000..c4085ae9f --- /dev/null +++ b/tests/publishers/fixtures/image-gallery002.yaml @@ -0,0 +1,22 @@ +publishers: + - image-gallery: + - gallery-type: archived-images-gallery + title: Gallery 1 + includes: path/images + image-width: 100 + unstable-if-no-artifacts: true + - gallery-type: archived-images-gallery + - gallery-type: in-folder-comparative-gallery + title: Gallery 3 + base-root-folder: path/images3 + image-width: 321 + image-inner-width: 111 + unstable-if-no-artifacts: true + - gallery-type: in-folder-comparative-gallery + - gallery-type: multiple-folder-comparative-gallery + title: Gallery 5 + base-root-folder: path/images5 + image-width: 444 + image-inner-width: 333 + unstable-if-no-artifacts: true + - gallery-type: multiple-folder-comparative-gallery diff --git a/tests/publishers/fixtures/image-gallery003.xml b/tests/publishers/fixtures/image-gallery003.xml new file mode 100644 index 000000000..a099b0f08 --- /dev/null +++ b/tests/publishers/fixtures/image-gallery003.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="utf-8"?> +<project> + <publishers> + <org.jenkinsci.plugins.imagegallery.ImageGalleryRecorder> + <imageGalleries> + <org.jenkinsci.plugins.imagegallery.imagegallery.ArchivedImagesGallery> + <title>Gallery 1 + 100 + False + path/images + + + + + diff --git a/tests/publishers/fixtures/image-gallery003.yaml b/tests/publishers/fixtures/image-gallery003.yaml new file mode 100644 index 000000000..5bad7a64e --- /dev/null +++ b/tests/publishers/fixtures/image-gallery003.yaml @@ -0,0 +1,6 @@ +publishers: + - image-gallery: + - title: Gallery 1 + includes: path/images + image-width: 100 + unstable-if-no-artifacts: false