Skip to content

Commit

Permalink
ISSUE-37945 output not populated on failure (ansible#37952)
Browse files Browse the repository at this point in the history
* ISSUE-37945 output not populated on failure

This always includes output, but it is empty on failure.

* handle the other failcases as well
  • Loading branch information
hogarth-sv authored and ansibot committed Apr 5, 2018
1 parent 62c2b9a commit 509f52a
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/ansible/modules/web_infrastructure/jenkins_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def is_csrf_protection_enabled(module):
module.params['url'] + '/api/json',
method='GET')
if info["status"] != 200:
module.fail_json(msg="HTTP error " + str(info["status"]) + " " + info["msg"])
module.fail_json(msg="HTTP error " + str(info["status"]) + " " + info["msg"], output='')

content = to_native(resp.read())
return json.loads(content).get('useCrumbs', False)
Expand All @@ -126,7 +126,7 @@ def get_crumb(module):
module.params['url'] + '/crumbIssuer/api/json',
method='GET')
if info["status"] != 200:
module.fail_json(msg="HTTP error " + str(info["status"]) + " " + info["msg"])
module.fail_json(msg="HTTP error " + str(info["status"]) + " " + info["msg"], output='')

content = to_native(resp.read())
return json.loads(content)
Expand All @@ -148,14 +148,17 @@ def main():

if module.params['user'] is not None:
if module.params['password'] is None:
module.fail_json(msg="password required when user provided")
module.fail_json(msg="password required when user provided", output='')
module.params['url_username'] = module.params['user']
module.params['url_password'] = module.params['password']
module.params['force_basic_auth'] = True

if module.params['args'] is not None:
from string import Template
script_contents = Template(module.params['script']).substitute(module.params['args'])
try:
script_contents = Template(module.params['script']).substitute(module.params['args'])
except KeyError as err:
module.fail_json(msg="Error with templating variable: %s" % err, output='')
else:
script_contents = module.params['script']

Expand All @@ -172,12 +175,12 @@ def main():
timeout=module.params['timeout'])

if info["status"] != 200:
module.fail_json(msg="HTTP error " + str(info["status"]) + " " + info["msg"])
module.fail_json(msg="HTTP error " + str(info["status"]) + " " + info["msg"], output='')

result = to_native(resp.read())

if 'Exception:' in result and 'at java.lang.Thread' in result:
module.fail_json(msg="script failed with stacktrace:\n " + result)
module.fail_json(msg="script failed with stacktrace:\n " + result, output='')

module.exit_json(
output=result,
Expand Down

0 comments on commit 509f52a

Please sign in to comment.