Add Jenkins nagging to Lugito

Test Plan: Deploy I guess?

Reviewers: wxl, teward, apt-ghetto

Reviewed By: teward, apt-ghetto

Subscribers: apt-ghetto, #development_team

Tags: #development_team

Differential Revision: https://phab.lubuntu.me/D93
master
Simon Quigley 4 years ago
parent 9820ddb26b
commit 9b4358ed98

@ -16,6 +16,9 @@ import logging
import phabricator
import lugito
import requests
import json
import jenkinsapi.custom_exceptions
from jenkinsapi.jenkins import Jenkins
from string import Template
@ -88,5 +91,46 @@ class jenkins(object):
r.status_code, r.reason))
def auth_jenkins(self):
"""Authenticate with the Jenkins server"""
site = lugito.config.CONFIG["connectors"]["jenkins"]["site"]
user = lugito.config.CONFIG["connectors"]["jenkins"]["user"]
key = lugito.config.CONFIG["connectors"]["jenkins"]["api_key"]
server = Jenkins(site, username=user, password=key)
return server
def receive(self, proj_name):
"""Receive the project name and return the status of the last build"""
proj_name = json.loads(proj_name)["PROJECT"]
status = None
# Authenticate with the server
jenkins = self.auth_jenkins()
# Check if the project name matches a valid one on the server
# If it does, grab the job info, if it doesn't, stop
proj = None
for job in jenkins.get_jobs():
if job[0] == proj_name:
proj = job
if not proj:
return status
# Return the status of the last completed build
try:
status = proj[1].get_last_completed_build().get_status()
url = proj[1].get_last_completed_build().get_build_url()
return proj[0], status, url
except jenkinsapi.custom_exceptions.NoBuildData:
return None
def listen(self):
pass

@ -189,6 +189,17 @@ def jenkinstrigger():
return 'Ok'
@app.route("/jenkinsnag", methods=["POST"])
def jenkinsircnotify():
"""Jenkins IRC notifications"""
# Get the status of the most recent build to the given project
proj, status, link = jenkins_con.receive(request.data)
if status:
irc_con.send("Lubuntu CI", proj, status, link)
def run():
irc_con.connect()
launchpad_con.connect()

Loading…
Cancel
Save