Add support for Config File Provider to Maven Project module

Note: this is a port of the patch from commit 1e216835
https://review.openstack.org/gitweb?p=openstack-infra/jenkins-job-builder.git;a=commit;h=1e216835

This patch adds some detection logic to the code to detect if the
settings file starts with:
    org.jenkinsci.plugins.configfiles.maven.MavenSettingsConfig
or in the case of global-settings starts with:
    org.jenkinsci.plugins.configfiles.maven.GlobalMavenSettingsConfig

If true, the module will configure for Config File Provider as the
settings files.

See:
https://wiki.jenkins-ci.org/display/JENKINS/Config+File+Provider+Plugin

Change-Id: Ic7f4d4d676e67f5f96afc3bd412dea5a50bee79b
Signed-off-by: Thanh Ha <thanh.ha@linuxfoundation.org>
This commit is contained in:
Thanh Ha 2015-02-13 13:14:36 -05:00
parent c1d6ba6fbb
commit 26c79aa9f5
No known key found for this signature in database
GPG Key ID: B0CB27E00DA095AA
4 changed files with 86 additions and 17 deletions

View File

@ -1037,12 +1037,24 @@ def maven_target(parser, xml_parent, data):
(optional) (optional)
:arg str java-opts: java options for maven, can have multiples, :arg str java-opts: java options for maven, can have multiples,
must be in quotes (optional) must be in quotes (optional)
:arg str settings: Path to use as user settings.xml (optional) :arg str settings: Path to use as user settings.xml
:arg str global-settings: Path to use as global settings.xml (optional) It is possible to provide a ConfigFileProvider settings file, such as
see CFP Example below. (optional)
:arg str global-settings: Path to use as global settings.xml
It is possible to provide a ConfigFileProvider settings file, such as
see CFP Example below. (optional)
Requires the Jenkins `Config File Provider Plugin
<https://wiki.jenkins-ci.org/display/JENKINS/Config+File+Provider+Plugin>`_
for the Config File Provider "settings" and "global-settings" config.
Example: Example:
.. literalinclude:: /../../tests/builders/fixtures/maven-target-doc.yaml .. literalinclude:: /../../tests/builders/fixtures/maven-target-doc.yaml
CFP Example:
.. literalinclude:: /../../tests/builders/fixtures/maven-target002.yaml
:language: yaml :language: yaml
""" """
maven = XML.SubElement(xml_parent, 'hudson.tasks.Maven') maven = XML.SubElement(xml_parent, 'hudson.tasks.Maven')
@ -1059,15 +1071,43 @@ def maven_target(parser, xml_parent, data):
javaoptions = ' '.join(data.get('java-opts', [])) javaoptions = ' '.join(data.get('java-opts', []))
XML.SubElement(maven, 'jvmOptions').text = javaoptions XML.SubElement(maven, 'jvmOptions').text = javaoptions
if 'settings' in data: if 'settings' in data:
settings = XML.SubElement(maven, 'settings', # Support for Config File Provider
{'class': settings_file = str(data.get('settings'))
'jenkins.mvn.FilePathSettingsProvider'}) if settings_file.startswith(
'org.jenkinsci.plugins.configfiles.maven.MavenSettingsConfig'):
settings = XML.SubElement(
maven,
'settings',
{'class': 'org.jenkinsci.plugins.configfiles.maven.job.'
'MvnSettingsProvider'})
XML.SubElement(
settings,
'settingsConfigId').text = settings_file
else:
settings = XML.SubElement(
maven,
'settings',
{'class': 'jenkins.mvn.FilePathSettingsProvider'})
XML.SubElement(settings, 'path').text = data.get('settings') XML.SubElement(settings, 'path').text = data.get('settings')
else: else:
XML.SubElement(maven, 'settings', XML.SubElement(maven, 'settings',
{'class': {'class':
'jenkins.mvn.DefaultSettingsProvider'}) 'jenkins.mvn.DefaultSettingsProvider'})
if 'global-settings' in data: if 'global-settings' in data:
# Support for Config File Provider
global_settings_file = str(data.get('global-settings'))
if global_settings_file.startswith(
'org.jenkinsci.plugins.configfiles.maven.'
'GlobalMavenSettingsConfig'):
settings = XML.SubElement(
maven,
'globalSettings',
{'class': 'org.jenkinsci.plugins.configfiles.maven.job.'
'MvnGlobalSettingsProvider'})
XML.SubElement(
settings,
'settingsConfigId').text = global_settings_file
else:
provider = 'jenkins.mvn.FilePathGlobalSettingsProvider' provider = 'jenkins.mvn.FilePathGlobalSettingsProvider'
global_settings = XML.SubElement(maven, 'globalSettings', global_settings = XML.SubElement(maven, 'globalSettings',
{'class': provider}) {'class': provider})

View File

@ -37,19 +37,24 @@ in the :ref:`Job` definition.
a SNAPSHOT dependency is built or not. (default true) a SNAPSHOT dependency is built or not. (default true)
* **automatic-archiving** (`bool`): Activate automatic artifact archiving * **automatic-archiving** (`bool`): Activate automatic artifact archiving
(default true). (default true).
* **settings** (`str`): Path to custom maven settings file * **settings** (`str`): Path to custom maven settings file.
It is possible to provide a ConfigFileProvider settings file as well It is possible to provide a ConfigFileProvider settings file as well
org.jenkinsci.plugins.configfiles.maven.MavenSettingsConfig0123456789012 see CFP Example below. (optional)
(optional) * **global-settings** (`str`): Path to custom maven global settings file.
* **global-settings** (`str`): Path to custom maven global settings file
It is possible to provide a ConfigFileProvider settings file as well It is possible to provide a ConfigFileProvider settings file as well
org.jenkinsci.plugins.configfiles.maven.GlobalMavenSettingsConfig see CFP Example below. (optional)
0123456789012 (optional)
Requires the Jenkins `Config File Provider Plugin
<https://wiki.jenkins-ci.org/display/JENKINS/Config+File+Provider+Plugin>`_
for the Config File Provider "settings" and "global-settings" config.
Example: Example:
.. literalinclude:: /../../tests/general/fixtures/project-maven001.yaml .. literalinclude:: /../../tests/general/fixtures/project-maven001.yaml
CFP Example:
.. literalinclude:: /../../tests/general/fixtures/project-maven003.yaml
""" """
import xml.etree.ElementTree as XML import xml.etree.ElementTree as XML

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<postbuilders>
<hudson.tasks.Maven>
<targets>clean verify</targets>
<properties/>
<mavenName>mvn30</mavenName>
<usePrivateRepository>false</usePrivateRepository>
<settings class="org.jenkinsci.plugins.configfiles.maven.job.MvnSettingsProvider">
<settingsConfigId>org.jenkinsci.plugins.configfiles.maven.MavenSettingsConfig0123456789012</settingsConfigId>
</settings>
<globalSettings class="org.jenkinsci.plugins.configfiles.maven.job.MvnGlobalSettingsProvider">
<settingsConfigId>org.jenkinsci.plugins.configfiles.maven.GlobalMavenSettingsConfig0123456789012</settingsConfigId>
</globalSettings>
</hudson.tasks.Maven>
</postbuilders>
<builders/>
</project>

View File

@ -0,0 +1,6 @@
postbuilders:
- maven-target:
maven-version: mvn30
goals: clean verify
settings: org.jenkinsci.plugins.configfiles.maven.MavenSettingsConfig0123456789012
global-settings: org.jenkinsci.plugins.configfiles.maven.GlobalMavenSettingsConfig0123456789012