Skip to content

Instantly share code, notes, and snippets.

@waynr
Created December 7, 2016 20:38
Show Gist options
  • Save waynr/42d008fb937b42628b60f2935c27843a to your computer and use it in GitHub Desktop.
Save waynr/42d008fb937b42628b60f2935c27843a to your computer and use it in GitHub Desktop.
sqlalchemy jenkins metrics db query
#!/usr/bin/env python
import datetime
from sqlalchemy import create_engine, MetaData, Table
from sqlalchemy.orm import sessionmaker
engine = create_engine('postgres://meow:[email protected]/jenkins_meow')
meta = MetaData(bind=engine)
jenkins_runs = Table("jenkins_details_run", meta, autoload=True, autoload_with=engine)
Session = sessionmaker(bind=engine)
session = Session()
today = datetime.date.today()
yesterday = today - datetime.timedelta(1)
for jr in session.query(jenkins_runs).filter_by(startdate=yesterday):
print(jr.jobname)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment