forked from joestewart/aegir_cid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjenkinsmail.py
executable file
·46 lines (37 loc) · 1.29 KB
/
jenkinsmail.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#! /usr/bin/env python
import sys
import string
import os
from fabric.api import *
# Add a new site deployment job to Jenkins
def jenkins_project_deployment(filename):
email = open(filename, 'r')
args = [ ]
for line in email:
for key in [ "site", "install_profile", "aegirserver", "webserver", "dbserver", "makefile", "repo", "branch" ]:
if key in line:
splitter = string.split(line, "=")
splitter = string.split(splitter[1], ": ")
splitter = string.split(splitter[1], "\n")
args.append(splitter[0])
arguments = string.join(args, ' ')
# Kick off the new deploy job in Jenkins
os.system('/usr/local/bin/newjenkinsjob %s' % arguments)
# Let's test to see if the request has come in via email or from CLI
def process_request():
if not sys.stdin.isatty():
rawmessage = sys.stdin.read()
filename = '/tmp/rawmessage.%s.txt' % os.getpid()
logfile = open(filename, 'w')
logfile.write(rawmessage)
logfile.close()
logfile = open(filename, 'r')
for line in logfile:
if 'Subject' in line:
_split_arg = string.split(line, ":")
subject = _split_arg[1]
if "New Aegir Site deployment" in subject:
jenkins_project_deployment(filename)
logfile.close()
if __name__ == "__main__":
process_request()