def _jobs_status(self): self._connect() for job in self.J.keys(): # Check if this job has last build try: build = self.J[job].get_last_build() except jenkinsapi.custom_exceptions.NoBuildData: build = None if build: buildno = build.buildno # Status color status = build.get_status() if build.get_status() == "SUCCESS": status = TColors.green(status) elif build.get_status() == "FAILURE": status = TColors.red(status) else: status = TColors.yellow(status) # Color duration duration = format_last_run(build.get_duration(), color=False) # Color timestamp last_run = format_last_run(build.get_timestamp(), color=False) else: buildno = " - " status = " - " duration = " - " last_run = " - " # update results self.results.append([job, buildno, last_run, status, duration]) # Print results headers = ["Name", "no", "Last Run", "Status", "Exec Time"] print_table(self.results, headers=headers)
def _format_summary_item(self, item): # TODO: smart print of time # Status Flag if len(self.inventory_hosts) > 1 and (self.answers["filter"] is None or self.answers["filter"] == "tag=all"): try: pop_host = self.inventory_hosts.index(item["host"]) self.inventory_hosts.pop(pop_host) item["host"] = "* " + item["host"] except: item["host"] = "? " + item["host"] # Tags color if "all" in item["only_tags"]: item["only_tags"] = ",".join(item["only_tags"]) else: item["only_tags"] = TColors.yellow(",".join(item["only_tags"])) item["skip_tags"] = ",".join(item["skip_tags"]) # Color recap if item["ok"] > 0: item["ok"] = TColors.green(item["ok"]) if item["failures"] > 0: item["failures"] = TColors.red(item["failures"]) if item["changed"] > 0: item["changed"] = TColors.yellow(item["changed"]) if item["unreachable"] > 0: item["unreachable"] = TColors.red(item["unreachable"]) if item["failures"] > 0 or item["unreachable"] > 0: item["host"] = TColors.red(item["host"]) elif item["changed"] > 0: item["host"] = TColors.yellow(item["host"]) else: item["host"] = TColors.green(item["host"]) # Color last run last_run = format_last_run(item["@timestamp"]) self.results.append([item["host"], last_run, item["play_name"], item["ok"], item["changed"], item["unreachable"], item["failures"], item["time"], item["only_tags"], item["skip_tags"], item["user"]])
def _format_summary_item(self, item): # TODO: smart print of time # Tags color if "all" in item["only_tags"]: item["only_tags"] = ",".join(item["only_tags"]) else: item["only_tags"] = TColors.yellow(",".join(item["only_tags"])) item["skip_tags"] = ",".join(item["skip_tags"]) # Color recap if item["ok"] > 0: item["ok"] = TColors.green(item["ok"]) if item["failures"] > 0: item["failures"] = TColors.red(item["failures"]) if item["changed"] > 0: item["changed"] = TColors.yellow(item["changed"]) if item["unreachable"] > 0: item["unreachable"] = TColors.red(item["unreachable"]) if item["failures"] > 0 or item["unreachable"] > 0: item["host"] = TColors.red(item["host"]) elif item["changed"] > 0: item["host"] = TColors.yellow(item["host"]) else: item["host"] = TColors.green(item["host"]) # Color last run last_run = format_last_run(item["@timestamp"], color=False) self.results.append([item["host"], last_run, item["play_name"], item["ok"], item["changed"], item["unreachable"], item["failures"], item["time"], item["only_tags"], item["skip_tags"], item["user"]])
def _projects_detail(self): self._connect() job_name = self.arguments.get("<jobname>") try: project = self.J[job_name] except jenkinsapi.custom_exceptions.UnknownJob: print "Error '" + TColors.red(job_name) + "' does not exist" exit(1) first_build = project.get_first_buildnumber() last_build = project.get_last_buildnumber() r_limit = self.arguments.get("--rlimit") if (last_build - first_build) > int(r_limit): first_build = last_build - int(r_limit) for buildno in range(first_build, last_build): try: build = project.get_build(buildno) except jenkinsapi.custom_exceptions.NoBuildData: build = None if build: # Status color status = build.get_status() if build.get_status() == "SUCCESS": status = TColors.green(status) elif build.get_status() == "FAILURE": status = TColors.red(status) if build: status = TColors.yellow(status) # Color duration duration = format_last_run(build.get_duration()) # Color timestamp last_run = format_last_run(build.get_timestamp(), color=False) self.results.append([buildno, last_run, duration, status]) # Print results headers = ["No.", "Last run", "Exec time", "Status"] print_table(self.results, headers=headers)
def _projects_status(self): self._connect() for job in self.J.keys(): name = job.split("-") if len(name) != 2: print "Error Jenkins job '{}' violates name SKIPPING JOB. Name example 'ansible-env-project_name.yml'"\ .format(name) return False # Check if this job has last build try: build = self.J[job].get_last_build() except jenkinsapi.custom_exceptions.NoBuildData: build = None if build: buildno = build.buildno # Status color status = build.get_status() if build.get_status() == "SUCCESS": status = TColors.green(status) elif build.get_status() == "FAILURE": status = TColors.red(status) else: status = TColors.yellow(status) # Color duration duration = format_last_run(build.get_duration()) # Color timestamp last_run = format_last_run(build.get_timestamp()) else: buildno = " - " status = " - " duration = " - " last_run = " - " # update results self.results.append([name[0], name[1], buildno, last_run, status, duration]) # Print results headers = ["ENV", "Name", "no", "Last Run", "Status", "Exec Time"] print_table(self.results, headers=headers)