From beeb50564e16ce5a575ff0445705dc149e8eca44 Mon Sep 17 00:00:00 2001 From: Joost van der Griendt Date: Sat, 13 Aug 2016 23:03:58 +0200 Subject: [PATCH] adding extra properties to sonar publisher Allows you to explicitly set which sonar configuration to use for the sonar analysis when having more than one sonar installation. In this case you are required to select which one to use, as there is no default fallback in the Jenkins plugin itself. Also added a similar option for configuring the maven installation to use. This does have a default value, the version used in the maven build in the same job. However, if for some reason you need a different version of maven for sonar analysis you have to be able to configure which one. Adds parameter installation-name for the sonar configuration, and maven-installation-name for the maven configuration. Change-Id: I013ea80688efa17334448e6394d312ca6854cf07 --- jenkins_jobs/modules/publishers.py | 10 +++++++++- tests/publishers/fixtures/sonar-full.xml | 2 ++ tests/publishers/fixtures/sonar-full.yaml | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py index 85c638816..29dab8bf2 100644 --- a/jenkins_jobs/modules/publishers.py +++ b/jenkins_jobs/modules/publishers.py @@ -2788,6 +2788,7 @@ def sonar(registry, xml_parent, data): `_ + :arg str installation-name: name of the Sonar instance to use (optional) :arg str jdk: JDK to use (inherited from the job if omitted). (optional) :arg str branch: branch onto which the analysis will be posted (default '') :arg str language: source code language (default '') @@ -2796,6 +2797,8 @@ def sonar(registry, xml_parent, data): (default false) :arg str maven-opts: options given to maven (default '') :arg str additional-properties: sonar analysis parameters (default '') + :arg str maven-installation-name: the name of the Maven installation + to use (optional) :arg dict skip-global-triggers: :Triggers: * **skip-when-scm-change** (`bool`): skip analysis when build triggered by scm (default false) @@ -2831,9 +2834,14 @@ def sonar(registry, xml_parent, data): sonar = XML.SubElement(xml_parent, 'hudson.plugins.sonar.SonarPublisher') sonar.set('plugin', 'sonar') - + if 'installation-name' in data: + XML.SubElement(sonar, 'installationName').text = data[ + 'installation-name'] if 'jdk' in data: XML.SubElement(sonar, 'jdk').text = data['jdk'] + if 'maven-installation-name' in data: + XML.SubElement(sonar, 'mavenInstallationName').text = data[ + 'maven-installation-name'] mappings = [ ('branch', 'branch', ''), diff --git a/tests/publishers/fixtures/sonar-full.xml b/tests/publishers/fixtures/sonar-full.xml index 830adda43..1d1823904 100644 --- a/tests/publishers/fixtures/sonar-full.xml +++ b/tests/publishers/fixtures/sonar-full.xml @@ -2,7 +2,9 @@ + MySonar MyJdk + Maven3.3.3 myBranch java mypom.xml diff --git a/tests/publishers/fixtures/sonar-full.yaml b/tests/publishers/fixtures/sonar-full.yaml index 0aa1b45b6..5f9e276d0 100644 --- a/tests/publishers/fixtures/sonar-full.yaml +++ b/tests/publishers/fixtures/sonar-full.yaml @@ -1,10 +1,12 @@ publishers: - sonar: + installation-name: MySonar jdk: MyJdk branch: myBranch language: java root-pom: mypom.xml private-maven-repo: true + maven-installation-name: Maven3.3.3 maven-opts: -DskipTests additional-properties: -DsonarHostURL=http://example.com/ skip-global-triggers: