Add support to CFP in builders sections

- Adds additional support for Config File Provider to builder sections
- Move builder/wrapper configuration to a common helper function for
  reuse

Change-Id: Ie80a3abbd42bdd06d138dcd0c5beea26c9a81f26
Signed-off-by: Thanh Ha <thanh.ha@linuxfoundation.org>
This commit is contained in:
Thanh Ha 2015-03-15 10:57:55 -04:00
parent e1cc03e606
commit 24849929e1
No known key found for this signature in database
GPG Key ID: B0CB27E00DA095AA
9 changed files with 85 additions and 26 deletions

View File

@ -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
<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

View File

@ -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':

View File

@ -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
<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):

View File

@ -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

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<builders>
<org.jenkinsci.plugins.configfiles.builder.ConfigFileBuildStep plugin="config-file-provider">
<managedFiles>
<org.jenkinsci.plugins.configfiles.buildwrapper.ManagedFile>
<fileId>org.jenkinsci.plugins.configfiles.maven.MavenSettingsConfig0123456789012</fileId>
<targetLocation>target</targetLocation>
<variable>variable</variable>
</org.jenkinsci.plugins.configfiles.buildwrapper.ManagedFile>
</managedFiles>
</org.jenkinsci.plugins.configfiles.builder.ConfigFileBuildStep>
</builders>
</project>

View File

@ -0,0 +1,6 @@
builders:
- config-file-provider:
files:
- file-id: org.jenkinsci.plugins.configfiles.maven.MavenSettingsConfig0123456789012
target: target
variable: variable

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<buildWrappers>
<org.jenkinsci.plugins.configfiles.buildwrapper.ConfigFileBuildWrapper>
<org.jenkinsci.plugins.configfiles.buildwrapper.ConfigFileBuildWrapper plugin="config-file-provider">
<managedFiles>
<org.jenkinsci.plugins.configfiles.buildwrapper.ManagedFile>
<fileId>org.jenkinsci.plugins.configfiles.custom.CustomConfig1409250932722</fileId>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<buildWrappers>
<org.jenkinsci.plugins.configfiles.buildwrapper.ConfigFileBuildWrapper>
<org.jenkinsci.plugins.configfiles.buildwrapper.ConfigFileBuildWrapper plugin="config-file-provider">
<managedFiles>
<org.jenkinsci.plugins.configfiles.buildwrapper.ManagedFile>
<fileId>org.jenkinsci.plugins.configfiles.custom.CustomConfig1234</fileId>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<buildWrappers>
<org.jenkinsci.plugins.configfiles.buildwrapper.ConfigFileBuildWrapper>
<org.jenkinsci.plugins.configfiles.buildwrapper.ConfigFileBuildWrapper plugin="config-file-provider">
<managedFiles>
<org.jenkinsci.plugins.configfiles.buildwrapper.ManagedFile>
<fileId>org.jenkinsci.plugins.configfiles.custom.CustomConfig1234</fileId>