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:
parent
c1d6ba6fbb
commit
26c79aa9f5
@ -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,20 +1071,48 @@ 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(
|
||||||
XML.SubElement(settings, 'path').text = data.get('settings')
|
'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')
|
||||||
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:
|
||||||
provider = 'jenkins.mvn.FilePathGlobalSettingsProvider'
|
# Support for Config File Provider
|
||||||
global_settings = XML.SubElement(maven, 'globalSettings',
|
global_settings_file = str(data.get('global-settings'))
|
||||||
{'class': provider})
|
if global_settings_file.startswith(
|
||||||
XML.SubElement(global_settings, 'path').text = data.get(
|
'org.jenkinsci.plugins.configfiles.maven.'
|
||||||
'global-settings')
|
'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'
|
||||||
|
global_settings = XML.SubElement(maven, 'globalSettings',
|
||||||
|
{'class': provider})
|
||||||
|
XML.SubElement(global_settings, 'path').text = data.get(
|
||||||
|
'global-settings')
|
||||||
else:
|
else:
|
||||||
XML.SubElement(maven, 'globalSettings',
|
XML.SubElement(maven, 'globalSettings',
|
||||||
{'class':
|
{'class':
|
||||||
|
@ -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
|
||||||
|
18
tests/builders/fixtures/maven-target002.xml
Normal file
18
tests/builders/fixtures/maven-target002.xml
Normal 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>
|
6
tests/builders/fixtures/maven-target002.yaml
Normal file
6
tests/builders/fixtures/maven-target002.yaml
Normal 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
|
Loading…
Reference in New Issue
Block a user