Created
July 22, 2016 18:32
-
-
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.
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 = '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
To execute this script, Do we need to set any Environment variables ...?