Skip to content

Commit

Permalink
Merge pull request #53 from lyz-code/feat/add-wait-and-bell-flags
Browse files Browse the repository at this point in the history
* [feat] Add wait and bell flags for the console command
  • Loading branch information
LD250 authored Jun 19, 2017
2 parents f380c66 + 6958e5b commit b7a11bf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
18 changes: 17 additions & 1 deletion jenkins_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def stop(self, args):
else:
print("%s job is not running" % job_name)

def _get_build_number(self, job_name, build_number):
def _get_build_number(self, job_name, build_number=None):
info = self.jenkins.get_job_info(job_name)
if not info['lastBuild']:
return None
Expand Down Expand Up @@ -359,3 +359,19 @@ def building(self, args):
print("%s estimated time left %s" % (display_name, eta))
else:
print("Nothing is being built now")

def wait(self, args):
""" Wait for the next building job, if there is one currently running,
it will return immediately"""
job_name = self._check_job(args.job_name)
job_info = self.jenkins.get_job_info(args.job_name, 1)
build_number = self._get_build_number(job_name)

if not job_info:
job_info = {}
old_build_number = build_number
while build_number == old_build_number:
if job_info.get('lastBuild', {}).get('building'):
break
build_number = self._get_build_number(job_name)
sleep(args.interval)
7 changes: 7 additions & 0 deletions jenkins_cli/cli_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ def load_parser():
stop_parser = subparsers.add_parser('stop', help='Stop job')
stop_parser.add_argument('job_name', help='Job to stop')

wait_parser = subparsers.add_parser('wait',
help='Wait for the next building job')
wait_parser.add_argument('job_name', help='Job to wait')
wait_parser.add_argument('-t', '--interval',
help='refresh interval in seconds', default=3,
type=check_nonnegative)

console_parser = subparsers.add_parser('console', help='Show console for the build')
console_parser.add_argument('job_name', help='Job to show console for')
console_parser.add_argument('-b', '--build', help='job build number to show console for (if omitted, last build number is used)', default='')
Expand Down

0 comments on commit b7a11bf

Please sign in to comment.