From 9cff4f295ec8020fa3a3ac15795a344666596770 Mon Sep 17 00:00:00 2001 From: Artem Nikitin Date: Wed, 11 Mar 2020 15:09:00 +0300 Subject: Add execute-on parameter for post build steps executeOn setting is available for PostBuildStep since 2.0 version of the Post Build Script plugin. For previous plugin's version executeOn should be set on the PostBuildScript layer. Change-Id: I6b7c9ccfbd0a2d610499074675835e6b5d96cb17 Task: 39028 Story: 2007411 --- jenkins_jobs/modules/publishers.py | 37 +++++++++++++++++++++- tests/publishers/fixtures/postbuildscript-full.xml | 5 +++ .../publishers/fixtures/postbuildscript-full.yaml | 5 +++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py index 6c1de7ce..5567cd7d 100755 --- a/jenkins_jobs/modules/publishers.py +++ b/jenkins_jobs/modules/publishers.py @@ -4256,6 +4256,10 @@ def postbuildscript(registry, xml_parent, data): the scripts. Valid options: SUCCESS / UNSTABLE / FAILURE / NOT_BUILT / ABORTED (default 'SUCCESS') + * ** execute-on (`str`) - For matrix projects, scripts + can be run after each axis is built (`axes`), after + all axis of the matrix are built (`matrix`) or after + each axis AND the matrix are built (`both`). (default `both`) :arg list groovy-script: Paths to Groovy scripts @@ -4266,6 +4270,10 @@ def postbuildscript(registry, xml_parent, data): the scripts. Valid options: SUCCESS / UNSTABLE / FAILURE / NOT_BUILT / ABORTED (default 'SUCCESS') + * ** execute-on (`str`) - For matrix projects, scripts + can be run after each axis is built (`axes`), after + all axis of the matrix are built (`matrix`) or after + each axis AND the matrix are built (`both`). (default `both`) :arg list groovy: Inline Groovy @@ -4276,6 +4284,10 @@ def postbuildscript(registry, xml_parent, data): the scripts. Valid options: SUCCESS / UNSTABLE / FAILURE / NOT_BUILT / ABORTED (default 'SUCCESS') + * ** execute-on (`str`) - For matrix projects, scripts + can be run after each axis is built (`axes`), after + all axis of the matrix are built (`matrix`) or after + each axis AND the matrix are built (`both`). (default `both`) :arg list builders: Execute any number of supported Jenkins builders. @@ -4287,6 +4299,10 @@ def postbuildscript(registry, xml_parent, data): the scripts. Valid options: SUCCESS / UNSTABLE / FAILURE / NOT_BUILT / ABORTED (default 'SUCCESS') + * ** execute-on (`str`) - For matrix projects, scripts + can be run after each axis is built (`axes`), after + all axis of the matrix are built (`matrix`) or after + each axis AND the matrix are built (`both`). (default `both`) :arg bool mark-unstable-if-failed: Build will be marked unstable if job will be successfully completed but publishing script will return @@ -4300,7 +4316,6 @@ def postbuildscript(registry, xml_parent, data): :arg bool onfailure: Deprecated, replaced with script-only-if-failed :arg bool script-only-if-failed: Scripts and builders are run only if the build failed (default false) - :arg str execute-on: For matrix projects, scripts can be run after each axis is built (`axes`), after all axis of the matrix are built (`matrix`) or after each axis AND the matrix are built (`both`). @@ -4355,6 +4370,18 @@ def postbuildscript(registry, xml_parent, data): if version >= pkg_resources.parse_version("2.0"): + def add_execute_on(bs_data, result_xml): + valid_values = ("matrix", "axes", "both") + execute_on = bs_data.get("execute-on") + if not execute_on: + return + if execute_on not in valid_values: + raise JenkinsJobsException( + "execute-on must be one of %s, got %s" % valid_values, execute_on + ) + execute_on_xml = XML.SubElement(result_xml, "executeOn") + execute_on_xml.text = execute_on.upper() + ################ # Script Files # ################ @@ -4370,6 +4397,8 @@ def postbuildscript(registry, xml_parent, data): for result in gs_data.get("build-on", ["SUCCESS"]): XML.SubElement(results_xml, "string").text = result + add_execute_on(gs_data, x) + helpers.convert_mapping_to_xml( x, gs_data, script_mapping, fail_required=True ) @@ -4382,6 +4411,8 @@ def postbuildscript(registry, xml_parent, data): for result in gs_data.get("build-on", ["SUCCESS"]): XML.SubElement(results_xml, "string").text = result + add_execute_on(gs_data, x) + helpers.convert_mapping_to_xml( x, gs_data, script_mapping, fail_required=True ) @@ -4401,6 +4432,8 @@ def postbuildscript(registry, xml_parent, data): for result in gs_data.get("build-on", ["SUCCESS"]): XML.SubElement(results_xml, "string").text = result + add_execute_on(gs_data, x) + helpers.convert_mapping_to_xml( x, gs_data, groovy_mapping, fail_required=True ) @@ -4419,6 +4452,8 @@ def postbuildscript(registry, xml_parent, data): for result in bs_data.get("build-on", ["SUCCESS"]): XML.SubElement(results_xml, "string").text = result + add_execute_on(bs_data, x) + helpers.convert_mapping_to_xml( x, bs_data, builder_mapping, fail_required=True ) diff --git a/tests/publishers/fixtures/postbuildscript-full.xml b/tests/publishers/fixtures/postbuildscript-full.xml index 60d2ac48..f6a24073 100644 --- a/tests/publishers/fixtures/postbuildscript-full.xml +++ b/tests/publishers/fixtures/postbuildscript-full.xml @@ -20,6 +20,7 @@ ABORTED FAILURE + MATRIX SLAVE /fakepath/generic-two GENERIC @@ -29,6 +30,7 @@ SUCCESS UNSTABLE + AXES MASTER /fakepath/groovy GROOVY @@ -50,6 +52,7 @@ SUCCESS UNSTABLE + MATRIX MASTER println "Hello world!" @@ -71,6 +74,7 @@ println "Multi-line script" SUCCESS UNSTABLE + AXES MASTER @@ -84,6 +88,7 @@ println "Multi-line script" ABORTED FAILURE + BOTH SLAVE diff --git a/tests/publishers/fixtures/postbuildscript-full.yaml b/tests/publishers/fixtures/postbuildscript-full.yaml index d583b652..bc1325d3 100644 --- a/tests/publishers/fixtures/postbuildscript-full.yaml +++ b/tests/publishers/fixtures/postbuildscript-full.yaml @@ -13,12 +13,14 @@ publishers: - NOT_BUILT - ABORTED - FAILURE + execute-on: matrix groovy-script: - file-path: '/fakepath/groovy' role: MASTER build-on: - SUCCESS - UNSTABLE + execute-on: axes - file-path: '/fakepath/groovy-too' role: SLAVE build-on: @@ -30,6 +32,7 @@ publishers: build-on: - SUCCESS - UNSTABLE + execute-on: matrix content: 'println "Hello world!"' - role: SLAVE build-on: @@ -45,6 +48,7 @@ publishers: build-on: - SUCCESS - UNSTABLE + execute-on: axes build-steps: - shell: 'echo "Hello world!"' - role: SLAVE @@ -52,6 +56,7 @@ publishers: - NOT_BUILT - ABORTED - FAILURE + execute-on: both build-steps: - shell: 'echo "Hello world!"' - shell: 'echo "Goodbye world!"' -- cgit