Merge "Consolidate CFP settings into a common function"
This commit is contained in:
commit
64cb2f4ebf
@ -40,6 +40,7 @@ Example::
|
||||
import xml.etree.ElementTree as XML
|
||||
import jenkins_jobs.modules.base
|
||||
from jenkins_jobs.modules import hudson_model
|
||||
from jenkins_jobs.modules.helpers import config_file_provider_settings
|
||||
from jenkins_jobs.errors import JenkinsJobsException
|
||||
import logging
|
||||
|
||||
@ -1070,53 +1071,7 @@ def maven_target(parser, xml_parent, data):
|
||||
if 'java-opts' in data:
|
||||
javaoptions = ' '.join(data.get('java-opts', []))
|
||||
XML.SubElement(maven, 'jvmOptions').text = javaoptions
|
||||
if 'settings' in data:
|
||||
# Support for Config File Provider
|
||||
settings_file = str(data.get('settings'))
|
||||
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')
|
||||
else:
|
||||
XML.SubElement(maven, 'settings',
|
||||
{'class':
|
||||
'jenkins.mvn.DefaultSettingsProvider'})
|
||||
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'
|
||||
global_settings = XML.SubElement(maven, 'globalSettings',
|
||||
{'class': provider})
|
||||
XML.SubElement(global_settings, 'path').text = data.get(
|
||||
'global-settings')
|
||||
else:
|
||||
XML.SubElement(maven, 'globalSettings',
|
||||
{'class':
|
||||
'jenkins.mvn.DefaultGlobalSettingsProvider'})
|
||||
config_file_provider_settings(maven, data)
|
||||
|
||||
|
||||
def multijob(parser, xml_parent, data):
|
||||
|
57
jenkins_jobs/modules/helpers.py
Normal file
57
jenkins_jobs/modules/helpers.py
Normal file
@ -0,0 +1,57 @@
|
||||
import xml.etree.ElementTree as XML
|
||||
|
||||
|
||||
def config_file_provider_settings(xml_parent, data):
|
||||
settings = {
|
||||
'default-settings':
|
||||
'jenkins.mvn.DefaultSettingsProvider',
|
||||
'settings':
|
||||
'jenkins.mvn.FilePathSettingsProvider',
|
||||
'config-file-provider-settings':
|
||||
'org.jenkinsci.plugins.configfiles.maven.job.MvnSettingsProvider',
|
||||
'default-global-settings':
|
||||
'jenkins.mvn.DefaultGlobalSettingsProvider',
|
||||
'global-settings':
|
||||
'jenkins.mvn.FilePathGlobalSettingsProvider',
|
||||
'config-file-provider-global-settings':
|
||||
'org.jenkinsci.plugins.configfiles.maven.job.'
|
||||
'MvnGlobalSettingsProvider',
|
||||
}
|
||||
|
||||
if 'settings' in data:
|
||||
# Support for Config File Provider
|
||||
settings_file = str(data['settings'])
|
||||
if settings_file.startswith(
|
||||
'org.jenkinsci.plugins.configfiles.maven.MavenSettingsConfig'):
|
||||
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
|
||||
else:
|
||||
XML.SubElement(xml_parent, 'settings',
|
||||
{'class': settings['default-settings']})
|
||||
|
||||
if 'global-settings' in data:
|
||||
# Support for Config File Provider
|
||||
global_settings_file = str(data['global-settings'])
|
||||
if global_settings_file.startswith(
|
||||
'org.jenkinsci.plugins.configfiles.maven.'
|
||||
'GlobalMavenSettingsConfig'):
|
||||
gsettings = XML.SubElement(
|
||||
xml_parent, 'globalSettings',
|
||||
{'class': settings['config-file-provider-global-settings']})
|
||||
XML.SubElement(
|
||||
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
|
||||
else:
|
||||
XML.SubElement(xml_parent, 'globalSettings',
|
||||
{'class': settings['default-global-settings']})
|
@ -59,6 +59,7 @@ CFP Example:
|
||||
|
||||
import xml.etree.ElementTree as XML
|
||||
import jenkins_jobs.modules.base
|
||||
from jenkins_jobs.modules.helpers import config_file_provider_settings
|
||||
|
||||
|
||||
class Maven(jenkins_jobs.modules.base.Base):
|
||||
@ -73,22 +74,6 @@ class Maven(jenkins_jobs.modules.base.Base):
|
||||
'hudson.maven.local_repo.PerExecutorLocalRepositoryLocator',
|
||||
}
|
||||
|
||||
settings = {
|
||||
'default-settings':
|
||||
'jenkins.mvn.DefaultSettingsProvider',
|
||||
'settings':
|
||||
'jenkins.mvn.FilePathSettingsProvider',
|
||||
'config-file-provider-settings':
|
||||
'org.jenkinsci.plugins.configfiles.maven.job.MvnSettingsProvider',
|
||||
'default-global-settings':
|
||||
'jenkins.mvn.DefaultGlobalSettingsProvider',
|
||||
'global-settings':
|
||||
'jenkins.mvn.FilePathGlobalSettingsProvider',
|
||||
'config-file-provider-global-settings':
|
||||
'org.jenkinsci.plugins.configfiles.maven.job.'
|
||||
'MvnGlobalSettingsProvider',
|
||||
}
|
||||
|
||||
def root_xml(self, data):
|
||||
xml_parent = XML.Element('maven2-moduleset')
|
||||
if 'maven' not in data:
|
||||
@ -135,56 +120,7 @@ class Maven(jenkins_jobs.modules.base.Base):
|
||||
XML.SubElement(xml_parent, 'processPlugins').text = 'false'
|
||||
XML.SubElement(xml_parent, 'mavenValidationLevel').text = '-1'
|
||||
XML.SubElement(xml_parent, 'runHeadless').text = 'false'
|
||||
if 'settings' in data['maven']:
|
||||
# Support for Config File Provider
|
||||
settings_file = str(data['maven'].get('settings', ''))
|
||||
if settings_file.startswith(
|
||||
'org.jenkinsci.plugins.configfiles.maven.MavenSettingsConfig'):
|
||||
settings = XML.SubElement(
|
||||
xml_parent,
|
||||
'settings',
|
||||
{'class': self.settings['config-file-provider-settings']})
|
||||
XML.SubElement(
|
||||
settings,
|
||||
'settingsConfigId').text = settings_file
|
||||
else:
|
||||
settings = XML.SubElement(
|
||||
xml_parent,
|
||||
'settings',
|
||||
{'class': self.settings['settings']})
|
||||
XML.SubElement(settings, 'path').text = settings_file
|
||||
else:
|
||||
XML.SubElement(
|
||||
xml_parent,
|
||||
'settings',
|
||||
{'class': self.settings['default-settings']})
|
||||
if 'global-settings' in data['maven']:
|
||||
# Support for Config File Provider
|
||||
global_settings_file = str(data['maven'].get(
|
||||
'global-settings', ''))
|
||||
if global_settings_file.startswith(
|
||||
'org.jenkinsci.plugins.configfiles.maven.'
|
||||
'GlobalMavenSettingsConfig'):
|
||||
settings = XML.SubElement(
|
||||
xml_parent,
|
||||
'globalSettings',
|
||||
{'class':
|
||||
self.settings['config-file-provider-global-settings']})
|
||||
XML.SubElement(
|
||||
settings,
|
||||
'settingsConfigId').text = global_settings_file
|
||||
else:
|
||||
settings = XML.SubElement(
|
||||
xml_parent,
|
||||
'globalSettings',
|
||||
{'class': self.settings['global-settings']})
|
||||
XML.SubElement(settings, 'path').text = str(
|
||||
data['maven'].get('global-settings', ''))
|
||||
else:
|
||||
XML.SubElement(
|
||||
xml_parent,
|
||||
'globalSettings',
|
||||
{'class': self.settings['default-global-settings']})
|
||||
config_file_provider_settings(xml_parent, data['maven'])
|
||||
|
||||
run_post_steps = XML.SubElement(xml_parent, 'runPostStepsIfResult')
|
||||
XML.SubElement(run_post_steps, 'name').text = 'FAILURE'
|
||||
|
Loading…
x
Reference in New Issue
Block a user