diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py index 889bbe9d4..8cc9fd0e9 100644 --- a/jenkins_jobs/modules/publishers.py +++ b/jenkins_jobs/modules/publishers.py @@ -2425,18 +2425,20 @@ def postbuildscript(parser, xml_parent, data): :arg list groovy-script: Paths to Groovy scripts :arg list groovy: Inline Groovy :arg list builders: Any supported builders, see :doc:`builders`. - :arg bool onsuccess: Scripts and builders are run only if the build succeed - (default True) - :arg bool onfailure: Scripts and builders are run only if the build fail - (default False) + :arg bool onsuccess: Deprecated, replaced with script-only-if-succeeded + :arg bool script-only-if-succeeded: Scripts and builders are run only if + the build succeeded (default True) + :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`). - The `onsuccess` and `onfailure` options are confusing. If you want - the post build to always run regardless of the build status, you - should set them both to `false`. + The `script-only-if-succeeded` and `bool script-only-if-failed` options are + confusing. If you want the post build to always run regardless of the build + status, you should set them both to `false`. Example: @@ -2503,10 +2505,21 @@ postbuildscript003.yaml # When to run the build? Note the plugin let one specify both options # although they are antinomic + # onsuccess and onfailure parameters are deprecated, this is to keep + # backwards compatability success_xml = XML.SubElement(pbs_xml, 'scriptOnlyIfSuccess') - success_xml.text = str(data.get('onsuccess', True)).lower() + if 'script-only-if-succeeded' in data: + success_xml.text = str(data.get('script-only-if-succeeded', + True)).lower() + else: + success_xml.text = str(data.get('onsuccess', True)).lower() + failure_xml = XML.SubElement(pbs_xml, 'scriptOnlyIfFailure') - failure_xml.text = str(data.get('onfailure', False)).lower() + if 'script-only-if-failed' in data: + failure_xml.text = str(data.get('script-only-if-failed', + False)).lower() + else: + failure_xml.text = str(data.get('onfailure', False)).lower() # TODO: we may want to avoid setting "execute-on" on non-matrix jobs, # either by skipping this part or by raising an error to let the user know diff --git a/tests/publishers/fixtures/postbuildscript001.yaml b/tests/publishers/fixtures/postbuildscript001.yaml index fd3af4bf3..66a4bdfa8 100644 --- a/tests/publishers/fixtures/postbuildscript001.yaml +++ b/tests/publishers/fixtures/postbuildscript001.yaml @@ -9,5 +9,5 @@ publishers: groovy: - "/** This is some inlined groovy */" - "/** Some more inlined groovy */" - onsuccess: False - onfailure: True + script-only-if-succeeded: False + script-only-if-failed: True diff --git a/tests/publishers/fixtures/postbuildscript004.yaml b/tests/publishers/fixtures/postbuildscript004.yaml index 1e883165f..b45b44e02 100644 --- a/tests/publishers/fixtures/postbuildscript004.yaml +++ b/tests/publishers/fixtures/postbuildscript004.yaml @@ -12,5 +12,5 @@ publishers: groovy-script: - '/tmp/one.groovy' - '/tmp/two.groovy' - onsuccess: False - onfailure: True + script-only-if-succeeded: False + script-only-if-failed: True