def job_status(client, args): print('Getting some info about %r' % args.job) #info = client.get_job_info(args.job) latest = jenkinsapi.get_latest_build(args.url, args.job) when = float(latest.get_timestamp()) / 1000. when = datetime.fromtimestamp(when).strftime('%Y-%m-%d %H:%M:%S') print('Latest build started at %s' % when) print('Build #%d' % latest.id()) running = latest.is_running() if not running: status = latest.is_good() if status: print('Build went ok. \o/') else: print('Build failed /o\\') else: print('Still running *now*...')
#-*- coding:utf-8 -*- from growl import GrowlPing from jenkinsapi.jenkins import Jenkins from jenkinsapi.api import get_latest_build import settings import time if __name__ == '__main__': while True: je = Jenkins(settings.JENKINS_URL) jobs_list = je.get_jobs_list() jobs_broken = [] for job_name in jobs_list: if '<disabled>true</disabled>'in je.get_job(job_name).get_config(): continue last_build = get_latest_build(settings.JENKINS_URL, job_name) if not last_build.is_good(): jobs_broken.append(job_name) if jobs_broken: p = GrowlPing() p.notify(jobs_broken) time.sleep(settings.REFRESH_JOBS_STATUS)
for opt, value in optlists: if opt in ("-h", "--help"): usage() sys.exit() elif opt in ("-c", "--command"): settings.DEPLOY_COMMAND = value if not settings.JENKINS_URL or not settings.JOBS_TO_VALIDATE or not settings.DEPLOY_COMMAND: usage() sys.exit() deploy = True print('Verificando se os jobs estão verdes e aptos para deploy...') for job in settings.JOBS_TO_VALIDATE: result = get_latest_build(settings.JENKINS_URL, job) print('%s - %s' % (result.is_good() ,job)) if not result.is_good(): deploy = False if deploy: print('Deploy aprovado!') print('Executando o deploy com o comando: %s' % settings.DEPLOY_COMMAND) print('Em execução...') run_command = commands.getstatusoutput(settings.DEPLOY_COMMAND) print('Resultado do deploy: %s' % run_command[0]) print('Log do deploy: %s' % run_command[1]) if run_command[0] != 0: raise Exception("O deploy Falhou!") else: