from common import runner
from common.envparas import *
from common import buildservice
-from common.send_mail import sendmail
import gbp.rpm
import gbp
'GERRIT_PATCHSET_NUMBER',
'GERRIT_BRANCH',
'BUILD_NUMBER',
+ 'BUILD_TAG',
'OBS_USERNAME',
'OBS_API_URL',
'OBS_OSCRC_PATH']
GERRIT_CMD = 'ssh -p %s %s@%s gerrit' % (GERRIT_SSHPORT, GERRIT_USERNAME, GERRIT_HOSTNAME)
GIT_URL = 'ssh://%s@%s:%s' % (GERRIT_USERNAME, GERRIT_HOSTNAME, GERRIT_SSHPORT)
+def sendmail(subject, body, mail_from, mail_to):
+ """ Prepare the envorinment parameter for trigger mail_sender job"""
+ mail_env = {}
+ mail_env['subject'] = subject
+ mail_env['body'] = body.replace('\n', '\\n')
+ mail_env['From'] = mail_from
+ mail_env['To'] = mail_to
+
+ with open('%s.env' %(BUILD_TAG),'w') as f:
+ for key in mail_env.keys():
+ f.write('%s=%s\n' %(key, mail_env[key]))
+
def end(rc = 0):
shutil.rmtree(tmpdir)
exit(rc)
from email.Utils import parseaddr, formataddr
def sendmail(from_email, to, msg, smtp_server):
+
+ if type(to) != list:
+ to = [to]
+
try:
s = smtplib.SMTP(smtp_server)
- s.sendmail(from_email, to, msg.as_string())
+ s.sendmail(from_email, ','.join(to), msg.as_string())
s.quit()
print "Email to %s sent succeeded" %(to)
except smtplib.SMTPException, e:
- print "Error: unable to send email: %s" % ( e )
+ raise Exception, "Error: unable to send email: %s" % ( e )
def makemail(subject = '', body = '', from_email = None, to = [],
cc = [], attachment = None, extra_headers = None):
'Cc',
'subject',
'body',
- 'targetpackage',
- 'template',
- 'reqinfo',
- 'comment',
'attachment',
'extra_headers',
'SMTP_SERVER']
export(envparas, locals())
+if To.startswith('[') and To.endswith(']'):
+ To = eval(To)
+
+if Cc.startswith('[') and Cc.endswith(']'):
+ Cc = eval(Cc)
+
message = makemail(subject = subject, body = body, from_email = From, to = To,
cc = Cc, attachment = attachment, extra_headers = extra_headers)
from common.envparas import *
from common import errors
from common import mysql
-from common.send_mail import sendmail
import gbp.rpm
'MYSQL_HOSTNAME',
'MYSQL_USERNAME',
'MYSQL_PASSWORD',
+ 'BUILD_TAG',
'MYSQL_DB_NAME']
export(envparas, locals())
GERRIT_CMD = 'ssh -p %s %s@%s gerrit' % (GERRIT_SSHPORT, GERRIT_USERNAME, GERRIT_HOSTNAME)
'newRev' : GERRIT_NEWREV}},
}
+
+
+def sendmail(subject, body, mail_from, mail_to):
+ """ Prepare the envorinment parameter for trigger mail_sender job"""
+ mail_env = {}
+ mail_env['subject'] = subject
+ mail_env['body'] = body.replace('\n', '\\n')
+ mail_env['From'] = mail_from
+ mail_env['To'] = mail_to
+
+ with open('%s.env' %(BUILD_TAG),'w') as f:
+ for key in mail_env.keys():
+ f.write('%s=%s\n' %(key, mail_env[key]))
+
def end(result = 'success'):
print 'execute result: %s' % result
db = mysql.Database(MYSQL_HOSTNAME, MYSQL_USERNAME, MYSQL_PASSWORD, MYSQL_DB_NAME)
from common.envparas import *
from common import errors
from common import mysql
-from common.send_mail import sendmail
import gbp.rpm
'JENKINS_HOME',
'OBS_API_URL',
'OBS_OSCRC_PATH',
+ 'BUILD_TAG',
'MYSQL_HOSTNAME',
'MYSQL_USERNAME',
'MYSQL_PASSWORD',
'newRev' : GERRIT_NEWREV}},
}
+
+def sendmail(subject, body, mail_from, mail_to):
+ """ Prepare the envorinment parameter for trigger mail_sender job"""
+ mail_env = {}
+ mail_env['subject'] = subject
+ mail_env['body'] = body.replace('\n', '\\n')
+ mail_env['From'] = mail_from
+ mail_env['To'] = mail_to
+
+ with open('%s.env' %(BUILD_TAG),'w') as f:
+ for key in mail_env.keys():
+ f.write('%s=%s\n' %(key, mail_env[key]))
+
def end(result = 'success'):
print 'execute result: %s' % result
# cleanup workspace