Skip to content

Commit f9382a8

Browse files
committed
info command: add last success build
1 parent d1d1a94 commit f9382a8

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

jenkins-cli/jenkins_cli.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,15 @@ def _check_job(self, job_name):
9191

9292
def info(self, args):
9393
job_name = self._check_job(args.job_name)
94-
job_info = self.jenkins.get_job_info(job_name, 1)['lastBuild']
94+
job_info = self.jenkins.get_job_info(job_name, 1)
9595
if not job_info:
9696
job_info = {}
97-
info = ("Last build name: %s\n"
97+
last_build = job_info.get('lastBuild', {})
98+
last_success_build = job_info.get('lastSuccessfulBuild', {})
99+
#from pprint import pprint
100+
#pprint(job_info)
101+
info = ("Last build name: %s (result: %s)\n"
102+
"Last success build name: %s\n"
98103
"Build started: %s\n"
99104
"Building now: %s\n"
100105
"Mercurial branch set: %s")
@@ -106,9 +111,11 @@ def info(self, args):
106111
revision = scm.find('revision')
107112
if revision is not None:
108113
rev = revision.text
109-
print info % (job_info.get('fullDisplayName', 'Not Built'),
110-
datetime.datetime.fromtimestamp(job_info['timestamp'] / 1000) if job_info else 'Not built',
111-
'Yes' if job_info.get('building') else 'No',
114+
print info % (last_build.get('fullDisplayName', 'Not Built'),
115+
last_build.get('result', 'Not Built'),
116+
last_success_build.get('fullDisplayName', 'Not Built'),
117+
datetime.datetime.fromtimestamp(last_build['timestamp'] / 1000) if last_build else 'Not built',
118+
'Yes' if last_build.get('building') else 'No',
112119
rev)
113120

114121
def set_branch(self, args):

0 commit comments

Comments
 (0)