Skip to content

Instantly share code, notes, and snippets.

@deekayen
Created September 5, 2017 14:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deekayen/7da2e3e845366e0bce12d84f4f8d6715 to your computer and use it in GitHub Desktop.
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.
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