Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing problems with current jenkins version #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions retaliation.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,15 +288,15 @@ def read_url(url):
return urllib2.urlopen(request).read()


def jenkins_get_responsible_user(job_name):
def jenkins_get_responsible_user(job_url):
# Call back to Jenkins and determin who broke the build. (Hacky)
# We do this by crudly parsing the changes on the last failed build

changes_url = JENKINS_SERVER + "/job/" + job_name + "/lastFailedBuild/changes"
changes_url = JENKINS_SERVER + "/" + job_url + "lastFailedBuild/changes"
changedata = read_url(changes_url)

# Look for the /user/[name] link
m = re.compile('/user/([^/"]+)').search(changedata)
m = re.compile('by <a href="/jenkins/user/([^/"]+)').search(changedata)
if m:
return m.group(1)
else:
Expand All @@ -315,10 +315,12 @@ def jenkins_wait_for_event():
data, addr = sock.recvfrom(8 * 1024)
try:
notification_data = json.loads(data)
status = notification_data["build"]["status"].upper()
phase = notification_data["build"]["phase"].upper()
if phase == "FINISHED" and status.startswith("FAIL"):
target = jenkins_get_responsible_user(notification_data["name"])
status = notification_data["build"]["status"].upper()
phase = notification_data["build"]["phase"].upper()
jobname = notification_data["name"]

if ( (phase == "FINISHED" or phase == "FINALIZED") and status.startswith("FAIL") ):
target = jenkins_get_responsible_user(notification_data["url"])
if target == None:
print "WARNING: Could not identify the user who broke the build!"
continue
Expand Down