From f966faccba8f839d2bad65d95ea2d1f33f17b26c Mon Sep 17 00:00:00 2001 From: Alfredo Deza Date: Mon, 26 Oct 2015 09:03:56 -0400 Subject: [PATCH] report exceptions better Signed-off-by: Alfredo Deza --- ansible/library/jenkins-node | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/ansible/library/jenkins-node b/ansible/library/jenkins-node index 06d307c1..adc5a0e4 100644 --- a/ansible/library/jenkins-node +++ b/ansible/library/jenkins-node @@ -16,12 +16,12 @@ options: username: description: - - The username to log-in with. + - The Jenkins username to log-in with. required: true password: description: - - The password to log-in with. + - The Jenkins password (or API token) to log-in with. required: true operation: @@ -76,7 +76,8 @@ options: description: - the ID of the user needed for authentication. Usually found in credentials.xml or via the url - {host}/credential-store/domain/_/credential/{id} + {host}/credential-store/domain/_/credential/{id}. By default this is an + SSH user account and key (see "launcher" above). host: description: @@ -233,7 +234,16 @@ def main(): remoteFS=remoteFS, ) except Exception as ex: - return module.fail_json(msg=ex.message) + # Ensure that errors going out to Jenkins, specifically the network + # requests, can be properly translated into meaningful errors so that + # Ansible can report those back. + if ex.__class__.__name__ == 'HTTPError': + msg = "HTTPError %s: %s" % (exc_obj.code, exc_obj.url) + else: + message = getattr(ex, 'message', None) + msg = getattr(ex, 'msg', message) + msg = "%s: %s" % (ex.__class__.__name__, msg) + return module.fail_json(msg=msg) args = {'changed': changed} if msg: -- 2.39.5