Merge "Updated BuildTimeoutWrapper plugin"

This commit is contained in:
Zuul 2020-11-16 14:06:38 +00:00 committed by Gerrit Code Review
commit 7c1c936478
4 changed files with 41 additions and 1 deletions

View File

@ -275,8 +275,13 @@ def timeout(registry, xml_parent, data):
:arg bool fail: Mark the build as failed (default false)
:arg bool abort: Mark the build as aborted (default false)
:arg bool abort-and-restart: Mark the build as aborted, then restart.
Count of restarts can be set via `max-restarts`
(default false) (Version >= 1.17).
:arg bool write-description: Write a message in the description
(default false)
:arg int max-restarts: Count of maximum restarts.
0 means without a limit (default 0) (Version >= 1.17).
:arg int timeout: Abort the build after this number of minutes (default 3)
:arg str timeout-var: Export an environment variable to reference the
timeout value (optional)
@ -430,9 +435,13 @@ def timeout(registry, xml_parent, data):
strategy_element, data, mapping, fail_required=True
)
all_actions = ["fail", "abort"]
actions = []
for action in ["fail", "abort"]:
if version is not None and version >= pkg_resources.parse_version("1.17"):
all_actions.append("abort-and-restart")
for action in all_actions:
if str(data.get(action, "false")).lower() == "true":
actions.append(action)
@ -444,6 +453,8 @@ def timeout(registry, xml_parent, data):
if description is not None:
actions.append("write-description")
max_restarts = data.get("max-restarts", "0")
operation_list = XML.SubElement(twrapper, "operationList")
for action in actions:
@ -452,6 +463,11 @@ def timeout(registry, xml_parent, data):
XML.SubElement(operation_list, fmt_str.format("Abort"))
elif action == "fail":
XML.SubElement(operation_list, fmt_str.format("Fail"))
elif action == "abort-and-restart":
abort_restart = XML.SubElement(
operation_list, fmt_str.format("AbortAndRestart")
)
XML.SubElement(abort_restart, "maxRestarts").text = str(max_restarts)
elif action == "write-description":
write_description = XML.SubElement(
operation_list, fmt_str.format("WriteDescription")

View File

@ -0,0 +1,3 @@
- longName: 'Jenkins build timeout plugin'
shortName: 'build-timeout'
version: "1.17"

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<buildWrappers>
<hudson.plugins.build__timeout.BuildTimeoutWrapper>
<strategy class="hudson.plugins.build_timeout.impl.AbsoluteTimeOutStrategy">
<timeoutMinutes>40</timeoutMinutes>
</strategy>
<operationList>
<hudson.plugins.build__timeout.operations.AbortAndRestartOperation>
<maxRestarts>2</maxRestarts>
</hudson.plugins.build__timeout.operations.AbortAndRestartOperation>
</operationList>
</hudson.plugins.build__timeout.BuildTimeoutWrapper>
</buildWrappers>
</project>

View File

@ -0,0 +1,6 @@
wrappers:
- timeout:
abort-and-restart: true
max-restarts: 2
timeout: 40
type: absolute