diff --git a/jenkins_jobs/modules/wrappers.py b/jenkins_jobs/modules/wrappers.py index c9b3db08c..6e903d7c7 100644 --- a/jenkins_jobs/modules/wrappers.py +++ b/jenkins_jobs/modules/wrappers.py @@ -20,15 +20,6 @@ Wrappers can alter the way the build is run as well as the build output. :Macro: wrapper :Entry Point: jenkins_jobs.wrappers -Example:: - - job: - name: test_job - - wrappers: - - timeout: - timeout: 90 - fail: true """ import xml.etree.ElementTree as XML @@ -75,6 +66,8 @@ def timeout(parser, xml_parent, data): :arg bool write-description: Write a message in the description (default false) :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) :arg str type: Timeout type to use (default absolute) :arg int elastic-percentage: Percentage of the three most recent builds where to declare a timeout (default 0) @@ -86,33 +79,22 @@ def timeout(parser, xml_parent, data): * **elastic** * **absolute** + Example: - Example:: + .. literalinclude:: /../../tests/wrappers/fixtures/timeout001.yaml - wrappers: - - timeout: - timeout: 90 - fail: true - type: absolute - - wrappers: - - timeout: - fail: false - type: likely-stuck - - wrappers: - - timeout: - fail: true - elastic-percentage: 150 - elastic-default-timeout: 90 - type: elastic + .. literalinclude:: /../../tests/wrappers/fixtures/timeout002.yaml + .. literalinclude:: /../../tests/wrappers/fixtures/timeout003.yaml """ twrapper = XML.SubElement(xml_parent, 'hudson.plugins.build__timeout.' 'BuildTimeoutWrapper') XML.SubElement(twrapper, 'timeoutMinutes').text = str( data.get('timeout', 3)) + timeout_env_var = data.get('timeout-var') + if timeout_env_var: + XML.SubElement(twrapper, 'timeoutEnvVar').text = str(timeout_env_var) XML.SubElement(twrapper, 'failBuild').text = str( data.get('fail', 'false')).lower() XML.SubElement(twrapper, 'writingDescription').text = str( diff --git a/tests/wrappers/fixtures/timeout001.xml b/tests/wrappers/fixtures/timeout001.xml new file mode 100644 index 000000000..34e0e287e --- /dev/null +++ b/tests/wrappers/fixtures/timeout001.xml @@ -0,0 +1,14 @@ + + + + + 90 + BUILD_TIMEOUT + true + false + 0 + 3 + absolute + + + \ No newline at end of file diff --git a/tests/wrappers/fixtures/timeout001.yaml b/tests/wrappers/fixtures/timeout001.yaml new file mode 100644 index 000000000..0d286ab5e --- /dev/null +++ b/tests/wrappers/fixtures/timeout001.yaml @@ -0,0 +1,6 @@ +wrappers: + - timeout: + timeout: 90 + timeout-var: 'BUILD_TIMEOUT' + fail: true + type: absolute diff --git a/tests/wrappers/fixtures/timeout002.xml b/tests/wrappers/fixtures/timeout002.xml new file mode 100644 index 000000000..b7e1c68f8 --- /dev/null +++ b/tests/wrappers/fixtures/timeout002.xml @@ -0,0 +1,13 @@ + + + + + 3 + false + false + 0 + 3 + likelyStuck + + + \ No newline at end of file diff --git a/tests/wrappers/fixtures/timeout002.yaml b/tests/wrappers/fixtures/timeout002.yaml new file mode 100644 index 000000000..1993efca1 --- /dev/null +++ b/tests/wrappers/fixtures/timeout002.yaml @@ -0,0 +1,4 @@ +wrappers: + - timeout: + fail: false + type: likely-stuck diff --git a/tests/wrappers/fixtures/timeout003.xml b/tests/wrappers/fixtures/timeout003.xml new file mode 100644 index 000000000..c62d6ea73 --- /dev/null +++ b/tests/wrappers/fixtures/timeout003.xml @@ -0,0 +1,14 @@ + + + + + 3 + BUILD_TIMEOUT + true + false + 150 + 90 + elastic + + + \ No newline at end of file diff --git a/tests/wrappers/fixtures/timeout003.yaml b/tests/wrappers/fixtures/timeout003.yaml new file mode 100644 index 000000000..ff9480581 --- /dev/null +++ b/tests/wrappers/fixtures/timeout003.yaml @@ -0,0 +1,7 @@ + wrappers: + - timeout: + timeout-var: 'BUILD_TIMEOUT' + fail: true + elastic-percentage: 150 + elastic-default-timeout: 90 + type: elastic