Created
September 5, 2017 14:14
-
-
Save deekayen/7da2e3e845366e0bce12d84f4f8d6715 to your computer and use it in GitHub Desktop.
A python script you could run in Jenkins to find all jobs which the latest build is older than 6 months.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from jenkins import Jenkins, JenkinsError, Job, Server | |
# http://jenkins-webapi.readthedocs.org/en/latest/ | |
from jira.client import JIRA | |
import re | |
import xml.etree.ElementTree as ET | |
import sys | |
import time | |
import requests | |
#Jenkins connection | |
jenkins_url = 'https://jenkins.example.com' | |
j = Jenkins(jenkins_url, 'username', 'nottherealpassword') | |
count = 0 | |
six_months_ago = (time.time() - 15768000) | |
for jobname in j.jobnames: | |
job = j.job(jobname) | |
try: | |
if j.job_exists(jobname): | |
if job.last_build.info['timestamp']: | |
# Jenkins appears to add microseconds to the timestamp. | |
epoch_time = job.last_build.info['timestamp'] / 1000 | |
if epoch_time < six_months_ago: | |
count += 1 | |
print '{}: {}'.format(count, jobname) | |
except: | |
continue |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment