Skip to content

Commit

Permalink
Merge pull request #45 from radomirbosak/fix-no-jobs
Browse files Browse the repository at this point in the history
Fix AttributeErrors for `stop` and `info` commands
  • Loading branch information
LD250 authored Jun 3, 2017
2 parents 7966629 + da363fb commit cda355c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions jenkins_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ def info(self, args):
job_info = self.jenkins.get_job_info(job_name, 1)
if not job_info:
job_info = {}
last_build = job_info.get('lastBuild', {})
last_success_build = job_info.get('lastSuccessfulBuild', {})
last_build = job_info.get('lastBuild') or {}
last_success_build = job_info.get('lastSuccessfulBuild') or {}
xml = self.jenkins.get_job_config(job_name)
root = ElementTree.fromstring(xml.encode('utf-8'))
scm_name, branch_node = self._get_scm_name_and_node(root)
Expand Down Expand Up @@ -247,8 +247,9 @@ def builds(self, args):
def stop(self, args):
job_name = self._check_job(args.job_name)
info = self.jenkins.get_job_info(job_name, 1)
build_number = info['lastBuild'].get('number')
if build_number and info['lastBuild'].get('building'):
last_build = info.get('lastBuild') or {}
build_number = last_build.get('number')
if build_number and last_build.get('building'):
stop_status = self.jenkins.stop_build(job_name, build_number)
print("%s: %s" % (job_name, 'stopped' if not stop_status else stop_status))
else:
Expand Down

0 comments on commit cda355c

Please sign in to comment.