From 55de2146757dc7badb310c1c153663e508b1613b Mon Sep 17 00:00:00 2001 From: Areum Cho Date: Sat, 23 Jun 2018 18:11:05 -0400 Subject: [PATCH] Add support for Packer plugin Change-Id: Idcb85f53656efb07a6aafe28f60ecafd9011fab4 Co-Authored-By: Tan Heng Yeow Signed-off-by: Tan Heng Yeow --- jenkins_jobs/modules/publishers.py | 70 +++++++++++++++++++ tests/publishers/fixtures/packer-full.xml | 24 +++++++ tests/publishers/fixtures/packer-full.yaml | 16 +++++ tests/publishers/fixtures/packer-minimal.xml | 14 ++++ tests/publishers/fixtures/packer-minimal.yaml | 3 + 5 files changed, 127 insertions(+) create mode 100644 tests/publishers/fixtures/packer-full.xml create mode 100644 tests/publishers/fixtures/packer-full.yaml create mode 100644 tests/publishers/fixtures/packer-minimal.xml create mode 100644 tests/publishers/fixtures/packer-minimal.yaml diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py index c20236b03..9c3325e6c 100644 --- a/jenkins_jobs/modules/publishers.py +++ b/jenkins_jobs/modules/publishers.py @@ -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 `. + + :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 diff --git a/tests/publishers/fixtures/packer-full.xml b/tests/publishers/fixtures/packer-full.xml new file mode 100644 index 000000000..ffd07e3b5 --- /dev/null +++ b/tests/publishers/fixtures/packer-full.xml @@ -0,0 +1,24 @@ + + + + + test name + test template + test template text + additional params + true + change to directory + global + + + test var + test content + + + test var 2 + test content 2 + + + + + diff --git a/tests/publishers/fixtures/packer-full.yaml b/tests/publishers/fixtures/packer-full.yaml new file mode 100644 index 000000000..93efcacb7 --- /dev/null +++ b/tests/publishers/fixtures/packer-full.yaml @@ -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 diff --git a/tests/publishers/fixtures/packer-minimal.xml b/tests/publishers/fixtures/packer-minimal.xml new file mode 100644 index 000000000..e5632749f --- /dev/null +++ b/tests/publishers/fixtures/packer-minimal.xml @@ -0,0 +1,14 @@ + + + + + test name + + + + false + + global + + + diff --git a/tests/publishers/fixtures/packer-minimal.yaml b/tests/publishers/fixtures/packer-minimal.yaml new file mode 100644 index 000000000..5ddbe505b --- /dev/null +++ b/tests/publishers/fixtures/packer-minimal.yaml @@ -0,0 +1,3 @@ +publishers: + - packer: + name: test name