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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
'''
Created on Aug 26, 2014
__author__ = "Elizabeth 'pidge' Flanagan"
__copyright__ = "Copyright 2012-2014, Intel Corp."
__credits__ = ["Elizabeth Flanagan"]
__license__ = "GPL"
__version__ = "2.0"
__maintainer__ = "Elizabeth Flanagan"
__email__ = "pidge@toganlabs.com"
'''
from buildbot.steps.shell import ShellCommand
from buildbot.process.properties import Properties
import os
class SendQAEmail(ShellCommand):
haltOnFailure = False
flunkOnFailure = True
name = "SendQAEmail"
description = ["Sending QA Email"]
def __init__(self, factory, argdict=None, **kwargs):
self.factory = factory
description = ["Sending alert emails"]
for k, v in argdict.iteritems():
setattr(self, k, v)
# Timeout needs to be passed to LoggingBuildStep as a kwarg
self.timeout = 100000
kwargs['timeout']=self.timeout
ShellCommand.__init__(self, **kwargs)
def start(self):
if self.getProperty("custom_send_email") == 'True':
web_root = os.environ.get('WEB_ROOT')
web_url = os.environ.get('WEB_URL')
mailto = ""
mailcc = ""
mailbcc = ""
if os.environ.get('QA_MAIL_TO'):
mailto = os.environ.get('QA_MAIL_TO')
if os.environ.get('QA_MAIL_CC'):
mailcc = os.environ.get('QA_MAIL_CC')
if os.environ.get('QA_MAIL_BCC'):
mailbcc = os.environ.get('QA_MAIL_BCC')
mailsig = os.environ.get('QA_MAIL_SIG')
properties = self.build.getProperties().asDict()
repoprops = {}
mailsubject = "Build available for QA"
email_base = '''
A build identified as needing QA has finished on the autobuilder. This
build is located at:\n\n
%s''' % (self.getProperty('DEST').replace(web_root, web_url))
if str(self.getProperty("custom_release_me")) == "True":
is_milestone = self.getProperty("custom_is_milestone")
milestone_number = self.getProperty("custom_milestone_number")
rc_number = self.getProperty("custom_rc_number")
if is_milestone == "False":
snapshot = "."+rc_number
elif is_milestone == "True" and milestone_number is not "" and rc_number is not "":
snapshot = "_"+milestone_number+"."+rc_number
else:
snapshot = ""
prefix = snapshot
poky_name = self.getProperty("custom_poky_name")+prefix
poky_number = self.getProperty("custom_poky_number")+prefix
yocto_number = self.getProperty("custom_yocto_number")+prefix
rel_name = 'yocto-'+ yocto_number
email_base = '''
A release candidate build for %s is now available at:\n\n
%s\n\n
Please begin QA on this build as soon as possible.''' % (rel_name, self.getProperty('DEST').replace(web_root, web_url))
mailsubject = "Release Candidate Build for " + rel_name + " now available."
for k, v in properties.iteritems():
if "repourl_" in k:
name = k.replace("repourl_", '')
repourl = str(v[0])
githash = properties["commit_"+name][0]
repoprops[name]=repourl, githash
email_body = '\n\nBuild hash information: \n'
for k, v in repoprops.iteritems():
email_body = email_body + '%s : %s \n' % (k, v[1])
email_header = ""
if mailto is not None and mailto is not "":
email_header += "To: " + mailto + "\n"
if mailcc is not None and mailcc is not "":
email_header += "Cc: " + mailcc + "\n"
if mailbcc is not None and mailbcc is not "":
email_header += "Bcc: " + mailbcc + "\n"
email_header += "Subject: " + mailsubject + "\n"
mailcmd = 'echo "' + email_header + "\n" + email_base + '\n' + email_body + '\n' + mailsig + ' " | sendmail -t'
self.command = mailcmd
else:
self.command = 'echo "Not a QA build"'
ShellCommand.start(self)
|