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
This commit is contained in:
Artem Nikitin 2020-03-11 15:09:00 +03:00 committed by Thanh Ha (zxiiro)
parent f0fa1a7140
commit 9cff4f295e
3 changed files with 46 additions and 1 deletions

View File

@ -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
)

View File

@ -20,6 +20,7 @@
<string>ABORTED</string>
<string>FAILURE</string>
</results>
<executeOn>MATRIX</executeOn>
<role>SLAVE</role>
<filePath>/fakepath/generic-two</filePath>
<scriptType>GENERIC</scriptType>
@ -29,6 +30,7 @@
<string>SUCCESS</string>
<string>UNSTABLE</string>
</results>
<executeOn>AXES</executeOn>
<role>MASTER</role>
<filePath>/fakepath/groovy</filePath>
<scriptType>GROOVY</scriptType>
@ -50,6 +52,7 @@
<string>SUCCESS</string>
<string>UNSTABLE</string>
</results>
<executeOn>MATRIX</executeOn>
<role>MASTER</role>
<content>println &quot;Hello world!&quot;</content>
</org.jenkinsci.plugins.postbuildscript.model.Script>
@ -71,6 +74,7 @@ println &quot;Multi-line script&quot;
<string>SUCCESS</string>
<string>UNSTABLE</string>
</results>
<executeOn>AXES</executeOn>
<role>MASTER</role>
<buildSteps>
<hudson.tasks.Shell>
@ -84,6 +88,7 @@ println &quot;Multi-line script&quot;
<string>ABORTED</string>
<string>FAILURE</string>
</results>
<executeOn>BOTH</executeOn>
<role>SLAVE</role>
<buildSteps>
<hudson.tasks.Shell>

View File

@ -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!"'