Update sonar plugin
- update sonar plugin to use convert xml - update sonar docstring - add plugin="sonar" attribute - update test cases Change-Id: I2882533a4e7a160ca8144727e7f0928452a36123
This commit is contained in:
parent
b56481cf8c
commit
195bf51df7
|
@ -2447,25 +2447,27 @@ def sonar(registry, xml_parent, data):
|
||||||
Analyzing+with+SonarQube+Scanner+for+Jenkins>`_
|
Analyzing+with+SonarQube+Scanner+for+Jenkins>`_
|
||||||
|
|
||||||
:arg str jdk: JDK to use (inherited from the job if omitted). (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 (optional)
|
:arg str branch: branch onto which the analysis will be posted (default '')
|
||||||
:arg str language: source code language (optional)
|
:arg str language: source code language (default '')
|
||||||
:arg str root-pom: Root POM (default 'pom.xml')
|
:arg str root-pom: Root POM (default 'pom.xml')
|
||||||
:arg bool private-maven-repo: If true, use private Maven repository.
|
:arg bool private-maven-repo: If true, use private Maven repository.
|
||||||
(default false)
|
(default false)
|
||||||
:arg str maven-opts: options given to maven (optional)
|
:arg str maven-opts: options given to maven (default '')
|
||||||
:arg str additional-properties: sonar analysis parameters (optional)
|
:arg str additional-properties: sonar analysis parameters (default '')
|
||||||
:arg dict skip-global-triggers:
|
:arg dict skip-global-triggers:
|
||||||
:Triggers: * **skip-when-scm-change** (`bool`): skip analysis when
|
:Triggers: * **skip-when-scm-change** (`bool`): skip analysis when
|
||||||
build triggered by scm
|
build triggered by scm (default false)
|
||||||
* **skip-when-upstream-build** (`bool`): skip analysis when
|
* **skip-when-upstream-build** (`bool`): skip analysis when
|
||||||
build triggered by an upstream build
|
build triggered by an upstream build (default false)
|
||||||
* **skip-when-envvar-defined** (`str`): skip analysis when
|
* **skip-when-envvar-defined** (`str`): skip analysis when
|
||||||
the specified environment variable is set to true
|
the specified environment variable is set to true
|
||||||
|
(default '')
|
||||||
:arg str settings: Path to use as user settings.xml. It is possible to
|
:arg str settings: Path to use as user settings.xml. It is possible to
|
||||||
provide a ConfigFileProvider settings file, see Example below. (optional)
|
provide a ConfigFileProvider settings file, see Example below.
|
||||||
|
(optional)
|
||||||
:arg str global-settings: Path to use as global settings.xml. It is
|
:arg str global-settings: Path to use as global settings.xml. It is
|
||||||
possible to provide a ConfigFileProvider settings file, see Example
|
possible to provide a ConfigFileProvider settings file, see Example
|
||||||
below. (optional)
|
below. (optional)
|
||||||
|
|
||||||
Requires the Jenkins :jenkins-wiki:`Config File Provider Plugin
|
Requires the Jenkins :jenkins-wiki:`Config File Provider Plugin
|
||||||
<Config+File+Provider+Plugin>`
|
<Config+File+Provider+Plugin>`
|
||||||
|
@ -2474,31 +2476,43 @@ def sonar(registry, xml_parent, data):
|
||||||
This publisher supports the post-build action exposed by the Jenkins
|
This publisher supports the post-build action exposed by the Jenkins
|
||||||
Sonar Plugin, which is triggering a Sonar Analysis with Maven.
|
Sonar Plugin, which is triggering a Sonar Analysis with Maven.
|
||||||
|
|
||||||
Example:
|
Minimal Example:
|
||||||
|
|
||||||
.. literalinclude:: /../../tests/publishers/fixtures/sonar001.yaml
|
.. literalinclude:: /../../tests/publishers/fixtures/sonar-minimal.yaml
|
||||||
|
:language: yaml
|
||||||
|
|
||||||
|
Full Example:
|
||||||
|
.. literalinclude:: /../../tests/publishers/fixtures/sonar-complete.yaml
|
||||||
:language: yaml
|
:language: yaml
|
||||||
"""
|
"""
|
||||||
|
|
||||||
sonar = XML.SubElement(xml_parent, 'hudson.plugins.sonar.SonarPublisher')
|
sonar = XML.SubElement(xml_parent, 'hudson.plugins.sonar.SonarPublisher')
|
||||||
|
sonar.set('plugin', 'sonar')
|
||||||
|
|
||||||
if 'jdk' in data:
|
if 'jdk' in data:
|
||||||
XML.SubElement(sonar, 'jdk').text = data['jdk']
|
XML.SubElement(sonar, 'jdk').text = data['jdk']
|
||||||
XML.SubElement(sonar, 'branch').text = data.get('branch', '')
|
|
||||||
XML.SubElement(sonar, 'language').text = data.get('language', '')
|
mappings = [
|
||||||
XML.SubElement(sonar, 'rootPom').text = data.get('root-pom', 'pom.xml')
|
('branch', 'branch', ''),
|
||||||
XML.SubElement(sonar, 'usePrivateRepository').text = str(
|
('language', 'language', ''),
|
||||||
data.get('private-maven-repo', False)).lower()
|
('root-pom', 'rootPom', 'pom.xml'),
|
||||||
XML.SubElement(sonar, 'mavenOpts').text = data.get('maven-opts', '')
|
('private-maven-repo', 'usePrivateRepository', False),
|
||||||
XML.SubElement(sonar, 'jobAdditionalProperties').text = \
|
('maven-opts', 'mavenOpts', ''),
|
||||||
data.get('additional-properties', '')
|
('additional-properties', 'jobAdditionalProperties', '')
|
||||||
|
]
|
||||||
|
helpers.convert_mapping_to_xml(sonar, data, mappings, fail_required=True)
|
||||||
|
|
||||||
if 'skip-global-triggers' in data:
|
if 'skip-global-triggers' in data:
|
||||||
data_triggers = data['skip-global-triggers']
|
data_triggers = data['skip-global-triggers']
|
||||||
triggers = XML.SubElement(sonar, 'triggers')
|
triggers = XML.SubElement(sonar, 'triggers')
|
||||||
XML.SubElement(triggers, 'skipScmCause').text = \
|
triggers_mappings = [
|
||||||
str(data_triggers.get('skip-when-scm-change', False)).lower()
|
('skip-when-scm-change', 'skipScmCause', False),
|
||||||
XML.SubElement(triggers, 'skipUpstreamCause').text = \
|
('skip-when-upstream-build', 'skipUpstreamCause', False),
|
||||||
str(data_triggers.get('skip-when-upstream-build', False)).lower()
|
('skip-when-envvar-defined', 'envVar', '')
|
||||||
XML.SubElement(triggers, 'envVar').text = \
|
]
|
||||||
data_triggers.get('skip-when-envvar-defined', '')
|
helpers.convert_mapping_to_xml(
|
||||||
|
triggers, data_triggers, triggers_mappings, fail_required=True)
|
||||||
|
|
||||||
helpers.config_file_provider_settings(sonar, data)
|
helpers.config_file_provider_settings(sonar, data)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<project>
|
<project>
|
||||||
<publishers>
|
<publishers>
|
||||||
<hudson.plugins.sonar.SonarPublisher>
|
<hudson.plugins.sonar.SonarPublisher plugin="sonar">
|
||||||
<jdk>MyJdk</jdk>
|
<jdk>MyJdk</jdk>
|
||||||
<branch>myBranch</branch>
|
<branch>myBranch</branch>
|
||||||
<language>java</language>
|
<language>java</language>
|
|
@ -0,0 +1,15 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<project>
|
||||||
|
<publishers>
|
||||||
|
<hudson.plugins.sonar.SonarPublisher plugin="sonar">
|
||||||
|
<branch/>
|
||||||
|
<language/>
|
||||||
|
<rootPom>pom.xml</rootPom>
|
||||||
|
<usePrivateRepository>false</usePrivateRepository>
|
||||||
|
<mavenOpts/>
|
||||||
|
<jobAdditionalProperties/>
|
||||||
|
<settings class="jenkins.mvn.DefaultSettingsProvider"/>
|
||||||
|
<globalSettings class="jenkins.mvn.DefaultGlobalSettingsProvider"/>
|
||||||
|
</hudson.plugins.sonar.SonarPublisher>
|
||||||
|
</publishers>
|
||||||
|
</project>
|
|
@ -0,0 +1,2 @@
|
||||||
|
publishers:
|
||||||
|
- sonar
|
|
@ -1,21 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<project>
|
|
||||||
<publishers>
|
|
||||||
<hudson.plugins.sonar.SonarPublisher>
|
|
||||||
<jdk>MyJdk</jdk>
|
|
||||||
<branch>myBranch</branch>
|
|
||||||
<language>java</language>
|
|
||||||
<rootPom>pom.xml</rootPom>
|
|
||||||
<usePrivateRepository>false</usePrivateRepository>
|
|
||||||
<mavenOpts>-DskipTests</mavenOpts>
|
|
||||||
<jobAdditionalProperties>-DsonarHostURL=http://example.com/</jobAdditionalProperties>
|
|
||||||
<triggers>
|
|
||||||
<skipScmCause>true</skipScmCause>
|
|
||||||
<skipUpstreamCause>true</skipUpstreamCause>
|
|
||||||
<envVar>SKIP_SONAR</envVar>
|
|
||||||
</triggers>
|
|
||||||
<settings class="jenkins.mvn.DefaultSettingsProvider"/>
|
|
||||||
<globalSettings class="jenkins.mvn.DefaultGlobalSettingsProvider"/>
|
|
||||||
</hudson.plugins.sonar.SonarPublisher>
|
|
||||||
</publishers>
|
|
||||||
</project>
|
|
|
@ -1,11 +0,0 @@
|
||||||
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
|
|
Loading…
Reference in New Issue