From b17790cc58c82865da2b0ddecb76610f919adbb3 Mon Sep 17 00:00:00 2001 From: Michael Jeanson Date: Fri, 20 Nov 2015 13:20:39 -0500 Subject: [PATCH] Add script-type to env-script wrapper Change-Id: Iac2c6cffd826369d1fd3be70cfc5dd906ee2ca56 Signed-off-by: Michael Jeanson --- jenkins_jobs/modules/wrappers.py | 18 ++++++++++++++++++ tests/wrappers/fixtures/env-script001.xml | 1 + tests/wrappers/fixtures/env-script002.xml | 10 ++++++++++ tests/wrappers/fixtures/env-script002.yaml | 5 +++++ 4 files changed, 34 insertions(+) create mode 100644 tests/wrappers/fixtures/env-script002.xml create mode 100644 tests/wrappers/fixtures/env-script002.yaml diff --git a/jenkins_jobs/modules/wrappers.py b/jenkins_jobs/modules/wrappers.py index 844c84307..ada8b07a2 100644 --- a/jenkins_jobs/modules/wrappers.py +++ b/jenkins_jobs/modules/wrappers.py @@ -806,6 +806,12 @@ def env_script(parser, xml_parent, data): `. :arg script-content: The script to run (default: '') + :arg str script-type: The script type. + + :script-types supported: + * **unix-script** (default) + * **power-shell** + * **batch-script** :arg only-run-on-parent: Only applicable for Matrix Jobs. If true, run only on the matrix parent job (default: false) @@ -816,6 +822,18 @@ def env_script(parser, xml_parent, data): """ el = XML.SubElement(xml_parent, 'com.lookout.jenkins.EnvironmentScript') XML.SubElement(el, 'script').text = data.get('script-content', '') + + valid_script_types = { + 'unix-script': 'unixScript', + 'power-shell': 'powerShell', + 'batch-script': 'batchScript', + } + script_type = data.get('script-type', 'unix-script') + if script_type not in valid_script_types: + raise InvalidAttributeError('script-type', script_type, + valid_script_types) + XML.SubElement(el, 'scriptType').text = valid_script_types[script_type] + only_on_parent = str(data.get('only-run-on-parent', False)).lower() XML.SubElement(el, 'onlyRunOnParent').text = only_on_parent diff --git a/tests/wrappers/fixtures/env-script001.xml b/tests/wrappers/fixtures/env-script001.xml index 267f4cb8e..23c92e40b 100644 --- a/tests/wrappers/fixtures/env-script001.xml +++ b/tests/wrappers/fixtures/env-script001.xml @@ -3,6 +3,7 @@ + unixScript true diff --git a/tests/wrappers/fixtures/env-script002.xml b/tests/wrappers/fixtures/env-script002.xml new file mode 100644 index 000000000..2c962a7b2 --- /dev/null +++ b/tests/wrappers/fixtures/env-script002.xml @@ -0,0 +1,10 @@ + + + + + + batchScript + true + + + diff --git a/tests/wrappers/fixtures/env-script002.yaml b/tests/wrappers/fixtures/env-script002.yaml new file mode 100644 index 000000000..05c67d025 --- /dev/null +++ b/tests/wrappers/fixtures/env-script002.yaml @@ -0,0 +1,5 @@ +wrappers: + - env-script: + script-content: 'echo foo=bar' + only-run-on-parent: true + script-type: 'batch-script'