Skip to content

Commit b67b079

Browse files
committed
+ uinteractive console
1 parent 380ad32 commit b67b079

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

jenkins-cli/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,15 @@ def main():
4141
console_parser = subparsers.add_parser('console', help='Show job history')
4242
console_parser.add_argument('job_name', help='Job to show history for')
4343
console_parser.add_argument('-n', help='Show first n num of the lines only(if n is negative, shows last n lines)', type=int)
44+
console_parser.add_argument('-i', help='Interactive console', default=False, action='store_true')
4445

4546
args = parser.parse_args()
4647
try:
4748
jenkins_cli.JenkinsCli(args).run_command(args)
4849
except jenkins_cli.jenkins.JenkinsException as e:
4950
print e
51+
except KeyboardInterrupt:
52+
print "Aborted"
5053
except jenkins_cli.CliException as e:
5154
print e
5255
print "Read jenkins --help"

jenkins-cli/jenkins_cli.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,24 @@ def stop(self, args):
143143
def console(self, args):
144144
job_name = self._check_job(args.job_name)
145145
info = self.jenkins.get_job_info(job_name)
146+
print info['lastBuild']
146147
build_number = info['lastBuild'].get('number')
147148
console_out = self.jenkins.get_build_console_output(job_name, build_number)
149+
console_out = console_out.split('\n')
150+
last_line_num = len(console_out)
148151
if args.n:
149-
sc = console_out.split('\n')
150-
console_out = "\n".join(sc[args.n:] if args.n < 0 else sc[:args.n])
151-
print console_out
152+
console_out = console_out[args.n:] if args.n < 0 else console_out[:args.n]
153+
print "\n".join(console_out)
154+
if args.i:
155+
build_info = self.jenkins.get_build_info(job_name, build_number)
156+
while build_info['building']:
157+
console_out = self.jenkins.get_build_console_output(job_name, build_number)
158+
console_out = console_out.split('\n')
159+
new_line_num = len(console_out)
160+
if new_line_num > last_line_num:
161+
print "\n".join(console_out[last_line_num:])
162+
last_line_num = new_line_num
163+
time.sleep(5)
152164

153165
def building(self, args):
154166
args.d = False

0 commit comments

Comments
 (0)