Skip to content

Commit

Permalink
Merge branch 'master' into issue176
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-hellings authored Sep 21, 2017
2 parents 27e0c48 + a0b0243 commit 4915f2c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
v 0.8.4
- Bump to linchpin 1.0.3 and Ansible >= 2.3.2 because of syntax errors (GH #176)
- Capture errors from jenkins-cli.jar more robustly (GH #151)
- Streamline installation of the Python pip module (GH #147)

v 0.8.3 (13 Sep 2017)
Expand Down
42 changes: 31 additions & 11 deletions cinch/library/jenkins_user_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,40 @@ def main():
process = process_named_args + process_positional_args
# The groovy code simply prints out the value of the API key, so we want
# to be able to capture that output
err, output = None, None
p = subprocess.Popen(process,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
output, err = p.communicate()
os.unlink(groovy.name)
success = False
# It's possible the Popen process has an error code for a whole host of
# reasons
if p.returncode == 0:
success = True
module.exit_json(api_key=output.strip(),
err=err,
changed=False,
success=success)
try:
output, err = p.communicate()
os.unlink(groovy.name)
# It's possible the Popen process has an error code for a whole host of
# reasons
if p.returncode == 0:
module.exit_json(api_key=output.strip(),
err=err,
changed=False,
success=True)
else:
msg = "Error occurred while executing jenkins-cli.jar"
except subprocess.CalledProcessError:
msg = "Error received while attempting to execute Java"
# If err and output are some type of empty, but not the empty string,
# then we reached this point without any output. If they are the empty
# string, then we reached this point but the subprocess output nothing
# on the specified pipe. Providing this data, or a status message such
# as these defaults, provides a better way for users to diagnose the
# problems encountered
if not err and err != "":
err = "No stderr detected"
if not output and output != "":
output = "No stdout detected"
# There are lots of reasons to fall through to here. But if we have, then
# something has most definitely gone wrong. We should report on that
module.fail_json(msg=msg,
stderr=err,
stdout=output,
api_key='')


main()

0 comments on commit 4915f2c

Please sign in to comment.