Skip to content

Instantly share code, notes, and snippets.

@Harini0805
Forked from deekayen/JenkinsOldBuilds.py
Created August 22, 2018 11:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Harini0805/2fa0ea7cf3b9e91759e4d16061fa56e5 to your computer and use it in GitHub Desktop.
Save Harini0805/2fa0ea7cf3b9e91759e4d16061fa56e5 to your computer and use it in GitHub Desktop.
List all Jenkins 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 = 'http://jenkinsmaster.example.com:8080'
j = Jenkins(jenkins_url, 'username', 'password')
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