Skip to content

Instantly share code, notes, and snippets.

@deekayen
Created July 22, 2016 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save deekayen/dcf3262331c1d10c8d119429479b50aa to your computer and use it in GitHub Desktop.
Save deekayen/dcf3262331c1d10c8d119429479b50aa 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
@Harini0805
Copy link

To execute this script, Do we need to set any Environment variables ...?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment