diff --git a/jenkins_jobs/modules/wrappers.py b/jenkins_jobs/modules/wrappers.py index 9b8e94c1b..516e7aa47 100644 --- a/jenkins_jobs/modules/wrappers.py +++ b/jenkins_jobs/modules/wrappers.py @@ -265,6 +265,7 @@ def timeout(parser, xml_parent, data): * **no-activity** * **elastic** * **absolute** + * **deadline** :arg int elastic-percentage: Percentage of the three most recent builds where to declare a timeout, only applies to **elastic** type. @@ -274,6 +275,12 @@ def timeout(parser, xml_parent, data): :arg int elastic-default-timeout: Timeout to use if there were no previous builds, only applies to **elastic** type. (default 3) + :arg str deadline-time: Build terminate automatically at next deadline time + (HH:MM:SS), only applies to **deadline** type. (default 0:00:00) + :arg int deadline-tolerance: Period in minutes after deadline when a job + should be immediately aborted, only applies to **deadline** type. + (default 1) + Example (Version < 1.14): .. literalinclude:: /../../tests/wrappers/fixtures/timeout/timeout001.yaml @@ -296,6 +303,9 @@ def timeout(parser, xml_parent, data): .. literalinclude:: /../../tests/wrappers/fixtures/timeout/version-1.14/elastic001.yaml + .. literalinclude:: + /../../tests/wrappers/fixtures/timeout/version-1.15/deadline001.yaml + """ prefix = 'hudson.plugins.build__timeout.' twrapper = XML.SubElement(xml_parent, prefix + 'BuildTimeoutWrapper') @@ -304,7 +314,8 @@ def timeout(parser, xml_parent, data): "Jenkins build timeout plugin") version = pkg_resources.parse_version(plugin_info.get("version", "0")) - valid_strategies = ['absolute', 'no-activity', 'likely-stuck', 'elastic'] + valid_strategies = ['absolute', 'no-activity', 'likely-stuck', 'elastic', + 'deadline'] if version >= pkg_resources.parse_version("1.14"): strategy = data.get('type', 'absolute') @@ -345,6 +356,18 @@ def timeout(parser, xml_parent, data): XML.SubElement(strategy_element, 'timeoutMinutesElasticDefault' ).text = str(data.get('elastic-default-timeout', 3)) + elif strategy == "deadline": + strategy_element = XML.SubElement( + twrapper, 'strategy', + {'class': "hudson.plugins.build_timeout." + "impl.DeadlineTimeOutStrategy"}) + deadline_time = str(data.get('deadline-time', '0:00:00')) + XML.SubElement(strategy_element, + 'deadlineTime').text = str(deadline_time) + deadline_tolerance = int(data.get('deadline-tolerance', 1)) + XML.SubElement(strategy_element, 'deadlineToleranceInMinutes' + ).text = str(deadline_tolerance) + actions = [] for action in ['fail', 'abort']: diff --git a/tests/wrappers/fixtures/timeout/version-1.15/deadline001.plugins_info.yaml b/tests/wrappers/fixtures/timeout/version-1.15/deadline001.plugins_info.yaml new file mode 100644 index 000000000..a7316a0d9 --- /dev/null +++ b/tests/wrappers/fixtures/timeout/version-1.15/deadline001.plugins_info.yaml @@ -0,0 +1,3 @@ +- longName: 'Jenkins build timeout plugin' + shortName: 'build-timeout' + version: "1.15" diff --git a/tests/wrappers/fixtures/timeout/version-1.15/deadline001.xml b/tests/wrappers/fixtures/timeout/version-1.15/deadline001.xml new file mode 100644 index 000000000..807abe752 --- /dev/null +++ b/tests/wrappers/fixtures/timeout/version-1.15/deadline001.xml @@ -0,0 +1,15 @@ + + + + + + 0:00:00 + 1 + + + + + BUILD_TIMEOUT + + + diff --git a/tests/wrappers/fixtures/timeout/version-1.15/deadline001.yaml b/tests/wrappers/fixtures/timeout/version-1.15/deadline001.yaml new file mode 100644 index 000000000..960dc4d6b --- /dev/null +++ b/tests/wrappers/fixtures/timeout/version-1.15/deadline001.yaml @@ -0,0 +1,6 @@ + wrappers: + - timeout: + deadline-time: '0:00:00' + deadline-tolerance: 1 + timeout-var: 'BUILD_TIMEOUT' + type: deadline