from common import obspkg
from common import utils
from common import git
+from common import gerrit
from common import runner
from common.envparas import *
from common import buildservice
'GERRIT_USERNAME',
'GERRIT_HOSTNAME',
'GERRIT_PROJECT',
- 'GERRIT_CHANGE_NUMBER',
'GERRIT_REFSPEC',
- 'GERRIT_PATCHSET_NUMBER',
'GERRIT_BRANCH',
+ 'GERRIT_CHANGE_OWNER',
+ 'GERRIT_PATCHSET_REVISION',
'BUILD_NUMBER',
'BUILD_TAG',
'OBS_USERNAME',
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):
+
+g=gerrit.Gerrit(GERRIT_HOSTNAME, GERRIT_USERNAME, GERRIT_SSHPORT)
+
+def sendmail(subject, body, mail_from, mail_to, attachment = None):
""" Prepare the envorinment parameter for trigger mail_sender job"""
mail_env = {}
mail_env['subject'] = subject
mail_env['From'] = mail_from
mail_env['To'] = mail_to
+ if attachment:
+ mail_env['attachment'] = attachment
+
with open('%s.env' %(BUILD_TAG),'w') as f:
for key in mail_env.keys():
f.write('%s=%s\n' %(key, mail_env[key]))
msg='[BUILD CHECK RESULT] This change is built against OBS project %s: \n\n %-15s%-15s%-15s' %(obs_dest_prj, "repository", "arch", "result")
+ return_value = 0
+
for repo in status.keys():
for arch in status[repo]:
msg = msg + '\n\n %-15s%-15s%-15s' %(repo, arch, status[repo][arch])
if status[repo][arch] != 'succeeded':
- buildlog_gz = "%s/buildlog-%s-%s-%s.log.gz" %(WORKSPACE, spec.name, arch, status[repo][arch])
+ return_value = -1
+ tempdir = tempfile.mkdtemp(prefix=WORKSPACE+'/')
+ buildlog_gz = "%s/buildlog-%s-%s-%s.log.gz" %(tempdir,spec.name, arch, status[repo][arch])
log=bs.getBuildLog(buildcheck_project, '%s/%s'%(repo,arch), spec.name)
f = gzip.open(buildlog_gz, "wb")
f.write(log)
f.close()
- sendmail('[BUILD CHECK RESULT]: Your change for %s is failed to build against %s' %(GERRIT_PROJECT, obs_dest_prj), msg, 'no-replay@tz-testing-jenkins.bj.intel.com', '%s' %GERRIT_CHANGE_OWNER_EMAIL, attachment = buildlog_gz)
- print 'The log file %s is deleted' %(buildlog_gz)
- os.remove(buildlog_gz)
+ sendmail('[BUILD CHECK RESULT]: Your change for %s is failed to build against %s' %(GERRIT_PROJECT, obs_dest_prj), msg, 'no-replay@tz-testing-jenkins.bj.intel.com', '%s' %GERRIT_CHANGE_OWNER, attachment = buildlog_gz)
+
if not status:
- runner.show('%s %s %s,%s --message \'"%s"\'' % (GERRIT_CMD, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, "[BUILD CHECK RESULT] The project %s is not ready for build, please contact the build systerm administrator"))
+ msg = "[BUILD CHECK RESULT] The project %s is not ready for build, please contact the build systerm administrator" %(buildcheck_project)
+ g.review(commit = GERRIT_PATCHSET_REVISION, message = msg)
end(1)
-
+
print 'The project %s is deleted on OBS' %(buildcheck_project)
bs.deleteProject(buildcheck_project)
print msg
- runner.show('%s %s %s,%s --message \'"%s"\'' % (GERRIT_CMD, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, msg))
- end()
+ g.review(commit = GERRIT_PATCHSET_REVISION, message = msg)
+
+ end(return_value)