From d1e4168594277b22f4c94f46848b921677e111e3 Mon Sep 17 00:00:00 2001 From: Holger Levsen Date: Fri, 10 Jul 2015 21:41:34 +0100 Subject: [PATCH] Adding support for Sidebar Plugin --- jenkins_jobs/modules/properties.py | 26 ++++++++++++++++++++++++ setup.cfg | 1 + tests/properties/fixtures/sidebar01.xml | 14 +++++++++++++ tests/properties/fixtures/sidebar01.yaml | 5 +++++ tests/properties/fixtures/sidebar02.xml | 20 ++++++++++++++++++ tests/properties/fixtures/sidebar02.yaml | 9 ++++++++ 6 files changed, 75 insertions(+) create mode 100644 tests/properties/fixtures/sidebar01.xml create mode 100644 tests/properties/fixtures/sidebar01.yaml create mode 100644 tests/properties/fixtures/sidebar02.xml create mode 100644 tests/properties/fixtures/sidebar02.yaml diff --git a/jenkins_jobs/modules/properties.py b/jenkins_jobs/modules/properties.py index 8abe10e29..6fed48802 100644 --- a/jenkins_jobs/modules/properties.py +++ b/jenkins_jobs/modules/properties.py @@ -202,6 +202,32 @@ def throttle(parser, xml_parent, data): XML.SubElement(throttle, 'configVersion').text = '1' +def sidebar(parser, xml_parent, data): + """yaml: sidebar + Allows you to add links in the sidebar. + Requires the Jenkins :jenkins-wiki:`Sidebar Plugin `. + + :arg str url: url to link to (optional) + :arg str text: text for the link (optional) + :arg str icon: path to icon (optional) + + Example: + + .. literalinclude:: /../../tests/properties/fixtures/sidebar02.yaml + """ + sidebar = xml_parent.find('hudson.plugins.sidebar__link.ProjectLinks') + if sidebar is None: + sidebar = XML.SubElement(xml_parent, + 'hudson.plugins.sidebar__link.ProjectLinks') + links = XML.SubElement(sidebar, 'links') + else: + links = sidebar.find('links') + action = XML.SubElement(links, 'hudson.plugins.sidebar__link.LinkAction') + XML.SubElement(action, 'url').text = str(data.get('url', '')) + XML.SubElement(action, 'text').text = str(data.get('text', '')) + XML.SubElement(action, 'icon').text = str(data.get('icon', '')) + + def inject(parser, xml_parent, data): """yaml: inject Allows you to inject environment variables into the build. diff --git a/setup.cfg b/setup.cfg index 8e3e06114..b6790c4b5 100644 --- a/setup.cfg +++ b/setup.cfg @@ -100,6 +100,7 @@ jenkins_jobs.properties = priority-sorter=jenkins_jobs.modules.properties:priority_sorter promoted-build=jenkins_jobs.modules.properties:promoted_build raw=jenkins_jobs.modules.general:raw + sidebar=jenkins_jobs.modules.properties:sidebar slave-utilization=jenkins_jobs.modules.properties:slave_utilization throttle=jenkins_jobs.modules.properties:throttle zeromq-event=jenkins_jobs.modules.properties:zeromq_event diff --git a/tests/properties/fixtures/sidebar01.xml b/tests/properties/fixtures/sidebar01.xml new file mode 100644 index 000000000..fa243e45c --- /dev/null +++ b/tests/properties/fixtures/sidebar01.xml @@ -0,0 +1,14 @@ + + + + + + + https://jenkins.debian.net/userContent/about.html + About jenkins.debian.net + /userContent/images/debian-swirl-24x24.png + + + + + diff --git a/tests/properties/fixtures/sidebar01.yaml b/tests/properties/fixtures/sidebar01.yaml new file mode 100644 index 000000000..cbc63bedf --- /dev/null +++ b/tests/properties/fixtures/sidebar01.yaml @@ -0,0 +1,5 @@ +properties: + - sidebar: + icon: /userContent/images/debian-swirl-24x24.png + text: About jenkins.debian.net + url: 'https://jenkins.debian.net/userContent/about.html' diff --git a/tests/properties/fixtures/sidebar02.xml b/tests/properties/fixtures/sidebar02.xml new file mode 100644 index 000000000..2637b3128 --- /dev/null +++ b/tests/properties/fixtures/sidebar02.xml @@ -0,0 +1,20 @@ + + + + + + + https://jenkins.debian.net/userContent/about.html + About jenkins.debian.net + /userContent/images/debian-swirl-24x24.png + + + https://jenkins.debian.net/view/reproducible + reproducible builds jobs + /userContent/images/debian-jenkins-24x24.png + + + + + + diff --git a/tests/properties/fixtures/sidebar02.yaml b/tests/properties/fixtures/sidebar02.yaml new file mode 100644 index 000000000..aedd7c55f --- /dev/null +++ b/tests/properties/fixtures/sidebar02.yaml @@ -0,0 +1,9 @@ +properties: + - sidebar: + url: https://jenkins.debian.net/userContent/about.html + text: About jenkins.debian.net + icon: /userContent/images/debian-swirl-24x24.png + - sidebar: + url: https://jenkins.debian.net/view/reproducible + text: reproducible builds jobs + icon: /userContent/images/debian-jenkins-24x24.png