Add Sonar Plugin support.

The Sonar Plugin provides both a builder and a publisher,
the later targeting Maven projects.

This commit adds support for the publisher, which is straightforward
to configure: no option is required, the plugin finds suitable
defaults by itself.

Several parameters can be provided though, which are transferred
as is to either Sonar or Maven. Analysis can also be skipped under
certain conditions.

Change-Id: I30744d0961d623cabf7c0780ab2f0d4db2cd9295
Reviewed-on: https://review.openstack.org/25073
Reviewed-by: Jeremy Stanley <fungi@yuggoth.org>
Approved: Monty Taylor <mordred@inaugust.com>
Reviewed-by: Monty Taylor <mordred@inaugust.com>
Tested-by: Jenkins
This commit is contained in:
Arnaud Fabre 2013-03-22 21:13:56 +01:00 committed by Jenkins
parent 1c0b7308c8
commit a164f01f4a
3 changed files with 69 additions and 0 deletions

View File

@ -1196,6 +1196,61 @@ def cifs(parser, xml_parent, data):
plugin_reference_tag)
def sonar(parser, xml_parent, data):
"""yaml: sonar
Sonar plugin support.
Requires the Jenkins `Sonar Plugin.
<http://docs.codehaus.org/pages/viewpage.action?pageId=116359341>`_
:arg str jdk: JDK to use (inherited from the job if omitted). (optional)
:arg str branch: branch onto which the analysis will be posted (optional)
:arg str language: source code language (optional)
:arg str maven-opts: options given to maven (optional)
:arg str additional-properties: sonar analysis parameters (optional)
:arg dict skip-global-triggers:
:Triggers: * **skip-when-scm-change** (`bool`): skip analysis when
build triggered by scm
* **skip-when-upstream-build** (`bool`): skip analysis when
build triggered by an upstream build
* **skip-when-envvar-defined** (`str`): skip analysis when
the specified environment variable is set to true
This publisher supports the post-build action exposed by the Jenkins
Sonar Plugin, which is triggering a Sonar Analysis with Maven.
Example::
publishers:
- sonar:
jdk: MyJdk
branch: myBranch
language: java
maven-opts: -DskipTests
additional-properties: -DsonarHostURL=http://example.com/
skip-global-triggers:
skip-when-scm-change: true
skip-when-upstream-build: true
skip-when-envvar-defined: SKIP_SONAR
"""
sonar = XML.SubElement(xml_parent, 'hudson.plugins.sonar.SonarPublisher')
if 'jdk' in data:
XML.SubElement(sonar, 'jdk').text = data['jdk']
XML.SubElement(sonar, 'branch').text = data.get('branch', '')
XML.SubElement(sonar, 'language').text = data.get('language', '')
XML.SubElement(sonar, 'mavenOpts').text = data.get('maven-opts', '')
XML.SubElement(sonar, 'jobAdditionalProperties').text = \
data.get('additional-properties', '')
if 'skip-global-triggers' in data:
data_triggers = data['skip-global-triggers']
triggers = XML.SubElement(sonar, 'triggers')
XML.SubElement(triggers, 'skipScmCause').text = \
str(data_triggers.get('skip-when-scm-change', False)).lower()
XML.SubElement(triggers, 'skipUpstreamCause').text = \
str(data_triggers.get('skip-when-upstream-build', False)).lower()
XML.SubElement(triggers, 'envVar').text = \
data_triggers.get('skip-when-envvar-defined', '')
class Publishers(jenkins_jobs.modules.base.Base):
sequence = 70

13
samples/sonar.yaml Normal file
View File

@ -0,0 +1,13 @@
- job:
name: test-sonar
publishers:
- sonar:
jdk: MyJdk
branch: myBranch
language: java
maven-opts: -DskipTests
additional-properties: -DsonarHostURL=http://example.com/
skip-global-triggers:
skip-when-scm-change: true
skip-when-upstream-build: true
skip-when-envvar-defined: SKIP_SONAR

View File

@ -116,6 +116,7 @@ setuptools.setup(
'copy-to-master=jenkins_jobs.modules.publishers:copy_to_master',
'jira=jenkins_jobs.modules.publishers:jira',
'cifs=jenkins_jobs.modules.publishers:cifs',
'sonar=jenkins_jobs.modules.publishers:sonar',
],
'jenkins_jobs.scm': [
'git=jenkins_jobs.modules.scm:git',