From 1f857fc8162472ab6b5354a2430b0cd50a49855a Mon Sep 17 00:00:00 2001 From: tanhengyeow Date: Sun, 27 May 2018 13:59:23 +0800 Subject: [PATCH] Improve support for EnvInject plugin Adds support for groovy script option and sandbox option. Updated new example YAML and XML files. Story: #2000922 Task: #3553 Change-Id: Iad44f9a0a776060c6fb1acfc3ebb44fa3c5acef2 --- jenkins_jobs/modules/wrappers.py | 24 +++++++++++++++------ tests/wrappers/fixtures/inject-full.xml | 18 ++++++++++++++++ tests/wrappers/fixtures/inject-full.yaml | 8 +++++++ tests/wrappers/fixtures/inject-minimal.xml | 13 +++++++++++ tests/wrappers/fixtures/inject-minimal.yaml | 2 ++ 5 files changed, 58 insertions(+), 7 deletions(-) create mode 100644 tests/wrappers/fixtures/inject-full.xml create mode 100644 tests/wrappers/fixtures/inject-full.yaml create mode 100644 tests/wrappers/fixtures/inject-minimal.xml create mode 100644 tests/wrappers/fixtures/inject-minimal.yaml diff --git a/jenkins_jobs/modules/wrappers.py b/jenkins_jobs/modules/wrappers.py index 0d94e2432..fa0212e70 100644 --- a/jenkins_jobs/modules/wrappers.py +++ b/jenkins_jobs/modules/wrappers.py @@ -920,15 +920,17 @@ def inject(registry, xml_parent, data): :arg str script-file: path to the script file (optional) :arg str script-content: contents of a script (optional) :arg bool load-from-master: load files from master (default false) + :arg str groovy-script: contents of the groovy script (optional) + :arg bool groovy-sandbox: use groovy sandbox (default false) - Example:: + Minimal Example: + + .. literalinclude:: /../../tests/wrappers/fixtures/inject-minimal.yaml + + Full Example: + + .. literalinclude:: /../../tests/wrappers/fixtures/inject-full.yaml - wrappers: - - inject: - properties-file: /usr/local/foo - properties-content: PATH=/foo/bar - script-file: /usr/local/foo.sh - script-content: echo $PATH """ eib = XML.SubElement(xml_parent, 'EnvInjectBuildWrapper') info = XML.SubElement(eib, 'info') @@ -941,6 +943,14 @@ def inject(registry, xml_parent, data): ] convert_mapping_to_xml(info, data, mapping, fail_required=False) + secure_groovy_script = XML.SubElement(info, 'secureGroovyScript') + mapping = [ + ('groovy-script', 'script', None), + ('groovy-sandbox', 'sandbox', False), + ] + convert_mapping_to_xml(secure_groovy_script, data, mapping, + fail_required=False) + def inject_ownership_variables(registry, xml_parent, data): """yaml: inject-ownership-variables diff --git a/tests/wrappers/fixtures/inject-full.xml b/tests/wrappers/fixtures/inject-full.xml new file mode 100644 index 000000000..260984754 --- /dev/null +++ b/tests/wrappers/fixtures/inject-full.xml @@ -0,0 +1,18 @@ + + + + + + example.prop full + EXAMPLE=foo-bar full + scriptfull.sh + test script content full + false + + + true + + + + + \ No newline at end of file diff --git a/tests/wrappers/fixtures/inject-full.yaml b/tests/wrappers/fixtures/inject-full.yaml new file mode 100644 index 000000000..b00171812 --- /dev/null +++ b/tests/wrappers/fixtures/inject-full.yaml @@ -0,0 +1,8 @@ +wrappers: + - inject: + properties-file: example.prop full + properties-content: EXAMPLE=foo-bar full + script-file: scriptfull.sh + script-content: test script content full + groovy-script: test groovy-script location full + groovy-sandbox: true \ No newline at end of file diff --git a/tests/wrappers/fixtures/inject-minimal.xml b/tests/wrappers/fixtures/inject-minimal.xml new file mode 100644 index 000000000..fdf578071 --- /dev/null +++ b/tests/wrappers/fixtures/inject-minimal.xml @@ -0,0 +1,13 @@ + + + + + + false + + false + + + + + \ No newline at end of file diff --git a/tests/wrappers/fixtures/inject-minimal.yaml b/tests/wrappers/fixtures/inject-minimal.yaml new file mode 100644 index 000000000..ec501151b --- /dev/null +++ b/tests/wrappers/fixtures/inject-minimal.yaml @@ -0,0 +1,2 @@ +wrappers: + - inject \ No newline at end of file