diff --git a/jenkins_jobs/modules/builders.py b/jenkins_jobs/modules/builders.py index a997871f0..2d5686c62 100644 --- a/jenkins_jobs/modules/builders.py +++ b/jenkins_jobs/modules/builders.py @@ -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_builder from jenkins_jobs.modules.helpers import config_file_provider_settings from jenkins_jobs.errors import JenkinsJobsException import logging @@ -1257,6 +1258,36 @@ def multijob(parser, xml_parent, data): ).text = kill_status +def config_file_provider(parser, xml_parent, data): + """yaml: config-file-provider + Provide configuration files (i.e., settings.xml for maven etc.) + which will be copied to the job's workspace. + Requires the Jenkins :jenkins-wiki:`Config File Provider Plugin + `. + + :arg list files: List of managed config files made up of three + parameters + + :files: * **file-id** (`str`) -- The identifier for the managed config + file + * **target** (`str`) -- Define where the file should be created + (optional) + * **variable** (`str`) -- Define an environment variable to be + used (optional) + + Example: + + .. literalinclude:: + ../../tests/builders/fixtures/config-file-provider01.yaml + :language: yaml + """ + cfp = XML.SubElement(xml_parent, + 'org.jenkinsci.plugins.configfiles.builder.' + 'ConfigFileBuildStep') + cfp.set('plugin', 'config-file-provider') + config_file_provider_builder(cfp, data) + + def grails(parser, xml_parent, data): """yaml: grails Execute a grails build step. Requires the :jenkins-wiki:`Jenkins Grails diff --git a/jenkins_jobs/modules/helpers.py b/jenkins_jobs/modules/helpers.py index e5ce23580..90daa9f5a 100644 --- a/jenkins_jobs/modules/helpers.py +++ b/jenkins_jobs/modules/helpers.py @@ -83,6 +83,25 @@ def build_trends_publisher(plugin_name, xml_element, data): xml_config.text = str(config_value) +def config_file_provider_builder(xml_parent, data): + """Builder / Wrapper helper""" + xml_files = XML.SubElement(xml_parent, 'managedFiles') + + files = data.get('files', []) + for file in files: + xml_file = XML.SubElement(xml_files, 'org.jenkinsci.plugins.' + 'configfiles.buildwrapper.ManagedFile') + file_id = file.get('file-id') + if file_id is None: + raise JenkinsJobsException("file-id is required for each " + "managed configuration file") + XML.SubElement(xml_file, 'fileId').text = str(file_id) + XML.SubElement(xml_file, 'targetLocation').text = file.get( + 'target', '') + XML.SubElement(xml_file, 'variable').text = file.get( + 'variable', '') + + def config_file_provider_settings(xml_parent, data): settings = { 'default-settings': diff --git a/jenkins_jobs/modules/wrappers.py b/jenkins_jobs/modules/wrappers.py index a45b0d7bd..fbc3fa421 100644 --- a/jenkins_jobs/modules/wrappers.py +++ b/jenkins_jobs/modules/wrappers.py @@ -27,6 +27,7 @@ import xml.etree.ElementTree as XML import jenkins_jobs.modules.base from jenkins_jobs.errors import JenkinsJobsException from jenkins_jobs.modules.builders import create_builders +from jenkins_jobs.modules.helpers import config_file_provider_builder def ci_skip(parser, xml_parent, data): @@ -64,15 +65,15 @@ def config_file_provider(parser, xml_parent, data): Requires the Jenkins :jenkins-wiki:`Config File Provider Plugin `. - :arg list files: List of managed config files made up of three\ + :arg list files: List of managed config files made up of three parameters - :Parameter: * **file-id** (`str`)\ - The identifier for the managed config file - :Parameter: * **target** (`str`)\ - Define where the file should be created (optional) - :Parameter: * **variable** (`str`)\ - Define an environment variable to be used (optional) + :files: * **file-id** (`str`) -- The identifier for the managed config + file + * **target** (`str`) -- Define where the file should be created + (optional) + * **variable** (`str`) -- Define an environment variable to be + used (optional) Example: @@ -80,23 +81,10 @@ def config_file_provider(parser, xml_parent, data): /../../tests/wrappers/fixtures/config-file-provider003.yaml :language: yaml """ - top = XML.SubElement(xml_parent, 'org.jenkinsci.plugins.configfiles.' + cfp = XML.SubElement(xml_parent, 'org.jenkinsci.plugins.configfiles.' 'buildwrapper.ConfigFileBuildWrapper') - xml_files = XML.SubElement(top, 'managedFiles') - - files = data.get('files', []) - for file in files: - xml_file = XML.SubElement(xml_files, 'org.jenkinsci.plugins.' - 'configfiles.buildwrapper.ManagedFile') - file_id = file.get('file-id') - if file_id is None: - raise JenkinsJobsException("file-id is required for each " - "managed configuration file") - XML.SubElement(xml_file, 'fileId').text = str(file_id) - XML.SubElement(xml_file, 'targetLocation').text = \ - file.get('target', '') - XML.SubElement(xml_file, 'variable').text = \ - file.get('variable', '') + cfp.set('plugin', 'config-file-provider') + config_file_provider_builder(cfp, data) def logfilesize(parser, xml_parent, data): diff --git a/setup.cfg b/setup.cfg index a2da53b55..77e5c8985 100644 --- a/setup.cfg +++ b/setup.cfg @@ -51,6 +51,7 @@ jenkins_jobs.builders = change-assembly-version=jenkins_jobs.modules.builders:change_assembly_version cmake=jenkins_jobs.modules.builders:cmake conditional-step=jenkins_jobs.modules.builders:conditional_step + config-file-provider=jenkins_jobs.modules.builders:config_file_provider copyartifact=jenkins_jobs.modules.builders:copyartifact critical-block-start=jenkins_jobs.modules.builders:critical_block_start critical-block-end=jenkins_jobs.modules.builders:critical_block_end diff --git a/tests/builders/fixtures/config-file-provider01.xml b/tests/builders/fixtures/config-file-provider01.xml new file mode 100644 index 000000000..3d1b3a925 --- /dev/null +++ b/tests/builders/fixtures/config-file-provider01.xml @@ -0,0 +1,14 @@ + + + + + + + org.jenkinsci.plugins.configfiles.maven.MavenSettingsConfig0123456789012 + target + variable + + + + + diff --git a/tests/builders/fixtures/config-file-provider01.yaml b/tests/builders/fixtures/config-file-provider01.yaml new file mode 100644 index 000000000..4166e9c05 --- /dev/null +++ b/tests/builders/fixtures/config-file-provider01.yaml @@ -0,0 +1,6 @@ +builders: + - config-file-provider: + files: + - file-id: org.jenkinsci.plugins.configfiles.maven.MavenSettingsConfig0123456789012 + target: target + variable: variable diff --git a/tests/wrappers/fixtures/config-file-provider001.xml b/tests/wrappers/fixtures/config-file-provider001.xml index 14f6e7646..b0cb6726b 100644 --- a/tests/wrappers/fixtures/config-file-provider001.xml +++ b/tests/wrappers/fixtures/config-file-provider001.xml @@ -1,7 +1,7 @@ - + org.jenkinsci.plugins.configfiles.custom.CustomConfig1409250932722 diff --git a/tests/wrappers/fixtures/config-file-provider002.xml b/tests/wrappers/fixtures/config-file-provider002.xml index cede51e85..cfbf86b70 100644 --- a/tests/wrappers/fixtures/config-file-provider002.xml +++ b/tests/wrappers/fixtures/config-file-provider002.xml @@ -1,7 +1,7 @@ - + org.jenkinsci.plugins.configfiles.custom.CustomConfig1234 diff --git a/tests/wrappers/fixtures/config-file-provider003.xml b/tests/wrappers/fixtures/config-file-provider003.xml index cbc9aedf5..ad265d788 100644 --- a/tests/wrappers/fixtures/config-file-provider003.xml +++ b/tests/wrappers/fixtures/config-file-provider003.xml @@ -1,7 +1,7 @@ - + org.jenkinsci.plugins.configfiles.custom.CustomConfig1234