From 26c79aa9f5a7e913b89b0668ae6b8481a9b0d9b4 Mon Sep 17 00:00:00 2001 From: Thanh Ha Date: Fri, 13 Feb 2015 13:14:36 -0500 Subject: [PATCH] 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 --- jenkins_jobs/modules/builders.py | 62 ++++++++++++++++---- jenkins_jobs/modules/project_maven.py | 17 ++++-- tests/builders/fixtures/maven-target002.xml | 18 ++++++ tests/builders/fixtures/maven-target002.yaml | 6 ++ 4 files changed, 86 insertions(+), 17 deletions(-) create mode 100644 tests/builders/fixtures/maven-target002.xml create mode 100644 tests/builders/fixtures/maven-target002.yaml diff --git a/jenkins_jobs/modules/builders.py b/jenkins_jobs/modules/builders.py index b597d4822..2d08d8b6e 100644 --- a/jenkins_jobs/modules/builders.py +++ b/jenkins_jobs/modules/builders.py @@ -1037,12 +1037,24 @@ def maven_target(parser, xml_parent, data): (optional) :arg str java-opts: java options for maven, can have multiples, must be in quotes (optional) - :arg str settings: Path to use as user settings.xml (optional) - :arg str global-settings: Path to use as global settings.xml (optional) + :arg str settings: Path to use as user settings.xml + 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 + `_ + for the Config File Provider "settings" and "global-settings" config. Example: .. literalinclude:: /../../tests/builders/fixtures/maven-target-doc.yaml + + CFP Example: + + .. literalinclude:: /../../tests/builders/fixtures/maven-target002.yaml :language: yaml """ 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', [])) XML.SubElement(maven, 'jvmOptions').text = javaoptions if 'settings' in data: - settings = XML.SubElement(maven, 'settings', - {'class': - 'jenkins.mvn.FilePathSettingsProvider'}) - XML.SubElement(settings, 'path').text = data.get('settings') + # 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: - provider = 'jenkins.mvn.FilePathGlobalSettingsProvider' - global_settings = XML.SubElement(maven, 'globalSettings', - {'class': provider}) - XML.SubElement(global_settings, 'path').text = data.get( - 'global-settings') + # 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': diff --git a/jenkins_jobs/modules/project_maven.py b/jenkins_jobs/modules/project_maven.py index 2054c0265..a3a1818ab 100755 --- a/jenkins_jobs/modules/project_maven.py +++ b/jenkins_jobs/modules/project_maven.py @@ -37,19 +37,24 @@ in the :ref:`Job` definition. a SNAPSHOT dependency is built or not. (default true) * **automatic-archiving** (`bool`): Activate automatic artifact archiving (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 - org.jenkinsci.plugins.configfiles.maven.MavenSettingsConfig0123456789012 - (optional) - * **global-settings** (`str`): Path to custom maven global settings file + see CFP Example below. (optional) + * **global-settings** (`str`): Path to custom maven global settings file. It is possible to provide a ConfigFileProvider settings file as well - org.jenkinsci.plugins.configfiles.maven.GlobalMavenSettingsConfig - 0123456789012 (optional) + see CFP Example below. (optional) + +Requires the Jenkins `Config File Provider Plugin +`_ +for the Config File Provider "settings" and "global-settings" config. Example: .. literalinclude:: /../../tests/general/fixtures/project-maven001.yaml +CFP Example: + + .. literalinclude:: /../../tests/general/fixtures/project-maven003.yaml """ import xml.etree.ElementTree as XML diff --git a/tests/builders/fixtures/maven-target002.xml b/tests/builders/fixtures/maven-target002.xml new file mode 100644 index 000000000..b6197611a --- /dev/null +++ b/tests/builders/fixtures/maven-target002.xml @@ -0,0 +1,18 @@ + + + + + clean verify + + mvn30 + false + + org.jenkinsci.plugins.configfiles.maven.MavenSettingsConfig0123456789012 + + + org.jenkinsci.plugins.configfiles.maven.GlobalMavenSettingsConfig0123456789012 + + + + + diff --git a/tests/builders/fixtures/maven-target002.yaml b/tests/builders/fixtures/maven-target002.yaml new file mode 100644 index 000000000..5c312dcda --- /dev/null +++ b/tests/builders/fixtures/maven-target002.yaml @@ -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