Fix CFP configuration for >=2.10.0

In CFP plugin version >=2.10.0 the JJB code completely breaks for Maven
settings due to the new support for freeform cfp id names. We can detect
a old style name simply by reading the starting of the name and setting
it to set settings_type=cfp to maintain support for the old versions of
this plugin. Otherwise the default settings_type will fall back to 'file'.

Users using cfp will now need to set 'settings-type: cfp' in their YAML
files if they need to pull in CFP settings. All other settings file
configuration will work as it did in the past.

Change-Id: I650d485de6ecc1d2ef8fad6580c0c315fadde168
Signed-off-by: Thanh Ha <thanh.ha@linuxfoundation.org>
This commit is contained in:
Thanh Ha 2016-04-20 21:05:25 -04:00
parent a725ca89af
commit 5cdbb719af
No known key found for this signature in database
GPG Key ID: B0CB27E00DA095AA
4 changed files with 81 additions and 13 deletions

View File

@ -108,6 +108,7 @@ def config_file_provider_builder(xml_parent, data):
def config_file_provider_settings(xml_parent, data):
SETTINGS_TYPES = ['file', 'cfp']
settings = {
'default-settings':
'jenkins.mvn.DefaultSettingsProvider',
@ -127,17 +128,28 @@ def config_file_provider_settings(xml_parent, data):
if 'settings' in data:
# Support for Config File Provider
settings_file = str(data['settings'])
settings_type = data.get('settings-type', 'file')
# For cfp versions <2.10.0 we are able to detect cfp via the config
# settings name.
if settings_file.startswith(
'org.jenkinsci.plugins.configfiles.maven.MavenSettingsConfig'):
'org.jenkinsci.plugins.configfiles.maven.'
'MavenSettingsConfig'):
settings_type = 'cfp'
if settings_type == 'file':
lsettings = XML.SubElement(
xml_parent, 'settings',
{'class': settings['settings']})
XML.SubElement(lsettings, 'path').text = settings_file
elif settings_type == 'cfp':
lsettings = XML.SubElement(
xml_parent, 'settings',
{'class': settings['config-file-provider-settings']})
XML.SubElement(lsettings, 'settingsConfigId').text = settings_file
else:
lsettings = XML.SubElement(
xml_parent, 'settings',
{'class': settings['settings']})
XML.SubElement(lsettings, 'path').text = settings_file
raise InvalidAttributeError(
'settings-type', settings_type, SETTINGS_TYPES)
else:
XML.SubElement(xml_parent, 'settings',
{'class': settings['default-settings']})
@ -145,9 +157,20 @@ def config_file_provider_settings(xml_parent, data):
if 'global-settings' in data:
# Support for Config File Provider
global_settings_file = str(data['global-settings'])
global_settings_type = data.get('settings-type', 'file')
# For cfp versions <2.10.0 we are able to detect cfp via the config
# settings name.
if global_settings_file.startswith(
'org.jenkinsci.plugins.configfiles.maven.'
'GlobalMavenSettingsConfig'):
global_settings_type = 'cfp'
if global_settings_type == 'file':
gsettings = XML.SubElement(xml_parent, 'globalSettings',
{'class': settings['global-settings']})
XML.SubElement(gsettings, 'path').text = global_settings_file
elif global_settings_type == 'cfp':
gsettings = XML.SubElement(
xml_parent, 'globalSettings',
{'class': settings['config-file-provider-global-settings']})
@ -155,9 +178,8 @@ def config_file_provider_settings(xml_parent, data):
gsettings,
'settingsConfigId').text = global_settings_file
else:
gsettings = XML.SubElement(xml_parent, 'globalSettings',
{'class': settings['global-settings']})
XML.SubElement(gsettings, 'path').text = global_settings_file
raise InvalidAttributeError(
'settings-type', global_settings_type, SETTINGS_TYPES)
else:
XML.SubElement(xml_parent, 'globalSettings',
{'class': settings['default-global-settings']})

View File

@ -52,12 +52,16 @@ in the :ref:`Job` definition.
(default false).
* **custom-workspace** (`str`): Path to the custom workspace. If no path is
provided, custom workspace is not used. (optional)
* **settings** (`str`): Path to custom maven settings file.
It is possible to provide a ConfigFileProvider settings file as well
see CFP Example below. (optional)
* **settings** (`str`): Path to custom maven settings file. If settings
type is 'file' then this is a Path. Otherwise it is the id for
ConfigFileProvider. (optional)
* **settings-type** (`str`): Type of settings file file|cfp.
(default: file)
* **global-settings** (`str`): Path to custom maven global settings file.
It is possible to provide a ConfigFileProvider settings file as well
see CFP Example below. (optional)
If settings type is 'file' then this is a Path. Otherwise it is the id
for ConfigFileProvider. (optional)
* **global-settings-type** (`str`): Type of settings file file|cfp.
(default: file)
* **post-step-run-condition** (`str`): Run the post-build steps only if the
build succeeds ('SUCCESS'), build succeeds or is unstable ('UNSTABLE'),
regardless of build result ('FAILURE'). (default 'FAILURE').

View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<maven2-moduleset>
<goals>deploy</goals>
<ignoreUpstremChanges>true</ignoreUpstremChanges>
<rootPOM>pom.xml</rootPOM>
<aggregatorStyleBuild>true</aggregatorStyleBuild>
<incrementalBuild>false</incrementalBuild>
<siteArchivingDisabled>false</siteArchivingDisabled>
<fingerprintingDisabled>false</fingerprintingDisabled>
<perModuleEmail>true</perModuleEmail>
<archivingDisabled>false</archivingDisabled>
<resolveDependencies>false</resolveDependencies>
<processPlugins>false</processPlugins>
<mavenValidationLevel>-1</mavenValidationLevel>
<runHeadless>false</runHeadless>
<settings class="org.jenkinsci.plugins.configfiles.maven.job.MvnSettingsProvider">
<settingsConfigId>test-settings</settingsConfigId>
</settings>
<globalSettings class="org.jenkinsci.plugins.configfiles.maven.job.MvnGlobalSettingsProvider">
<settingsConfigId>test-global-settings</settingsConfigId>
</globalSettings>
<runPostStepsIfResult>
<name>SUCCESS</name>
<ordinal>0</ordinal>
<color>BLUE</color>
</runPostStepsIfResult>
<actions/>
<keepDependencies>false</keepDependencies>
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
<concurrentBuild>false</concurrentBuild>
<canRoam>true</canRoam>
</maven2-moduleset>

View File

@ -0,0 +1,9 @@
project-type: maven
maven:
root-pom: pom.xml
goals: deploy
settings: test-settings
settings-type: cfp
global-settings: test-global-settings
global-settings-type: cfp
post-step-run-condition: SUCCESS