Merge "Add support for Packer plugin"

This commit is contained in:
Zuul 2019-04-09 01:45:23 +00:00 committed by Gerrit Code Review
commit 0cf0452d5d
5 changed files with 127 additions and 0 deletions

View File

@ -7793,6 +7793,76 @@ def tasks(registry, xml_parent, data):
thrsh_xml, thrsh_data, thrsh_mappings, fail_required=True)
def packer(registry, xml_parent, data):
"""yaml: packer
This plugin allows for a job to publish an image generated Packer
Requires the Jenkins :jenkins-wiki:`Packer Plugin <Packer+Plugin>`.
:arg str name: Name of the packer installation (required)
:arg str json-template: Path to a Packer JSON template file (default '')
:arg str json-template-text: Text of Packer JSON template (default '')
:arg str add-params: Specify which additional parameters
to pass to packer (default '')
:arg bool use-debug: adds -debug argument when packer executes
(default false)
:arg str change-dir: If set, the current directory will be changed
to this before starting packer (default '')
:arg str template-mode: Packer template option used (default global)
:template-mode values:
* **global**
* **file**
* **text**
:arg list file-entries: File entries for the packer
configuration (default [])
:arg str variable-name: Variable name for a file to used in the
configuration JSON (default '')
:arg str contents: File contents of the configuration JSON (default '')
Minimal Example:
.. literalinclude::
/../../tests/publishers/fixtures/packer-minimal.yaml
:language: yaml
Full Example:
.. literalinclude::
/../../tests/publishers/fixtures/packer-full.yaml
:language: yaml
"""
root = XML.SubElement(xml_parent,
'biz.neustar.jenkins.plugins.packer.PackerPublisher')
template_valid_types = ['global', 'file', 'text']
mapping = [
('name', 'name', None),
('json-template', 'jsonTemplate', ''),
('json-template-text', 'jsonTemplateText', ''),
('add-params', 'params', ''),
('use-debug', 'useDebug', False),
('change-dir', 'changeDir', ''),
('template-mode', 'templateMode', 'global', template_valid_types),
]
helpers.convert_mapping_to_xml(root, data, mapping, fail_required=True)
format_dict = {
'packer-file-entry':
'biz.neustar.jenkins.plugins.packer.PackerFileEntry'
}
if 'file-entries' in data:
file_entries_tag = XML.SubElement(root, 'fileEntries')
for file_entries in data['file-entries']:
for file, params in file_entries.items():
packer_file_entry_tag = XML.SubElement(file_entries_tag,
format_dict.get('packer-file-entry'))
XML.SubElement(packer_file_entry_tag,
'varFileName').text = params.get('variable-name', '')
XML.SubElement(packer_file_entry_tag,
'contents').text = params.get('contents', '')
class Publishers(jenkins_jobs.modules.base.Base):
sequence = 70

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<publishers>
<biz.neustar.jenkins.plugins.packer.PackerPublisher>
<name>test name</name>
<jsonTemplate>test template</jsonTemplate>
<jsonTemplateText>test template text</jsonTemplateText>
<params>additional params</params>
<useDebug>true</useDebug>
<changeDir>change to directory</changeDir>
<templateMode>global</templateMode>
<fileEntries>
<biz.neustar.jenkins.plugins.packer.PackerFileEntry>
<varFileName>test var</varFileName>
<contents>test content</contents>
</biz.neustar.jenkins.plugins.packer.PackerFileEntry>
<biz.neustar.jenkins.plugins.packer.PackerFileEntry>
<varFileName>test var 2</varFileName>
<contents>test content 2</contents>
</biz.neustar.jenkins.plugins.packer.PackerFileEntry>
</fileEntries>
</biz.neustar.jenkins.plugins.packer.PackerPublisher>
</publishers>
</project>

View File

@ -0,0 +1,16 @@
publishers:
- packer:
name: test name
json-template: test template
json-template-text: test template text
add-params: additional params
use-debug: true
change-dir: change to directory
template-mode: global
file-entries:
- files:
variable-name: test var
contents: test content
- files:
variable-name: test var 2
contents: test content 2

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<publishers>
<biz.neustar.jenkins.plugins.packer.PackerPublisher>
<name>test name</name>
<jsonTemplate/>
<jsonTemplateText/>
<params/>
<useDebug>false</useDebug>
<changeDir/>
<templateMode>global</templateMode>
</biz.neustar.jenkins.plugins.packer.PackerPublisher>
</publishers>
</project>

View File

@ -0,0 +1,3 @@
publishers:
- packer:
name: test name