Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
test
autotest-playwright-web-spd
Commits
26a5d4e4
Commit
26a5d4e4
authored
Sep 15, 2026
by
liguangyu06
Browse files
Send CI report mail with SMTP LOGIN instead of email-ext OAuth2.
parent
b63cb018
Changes
2
Hide whitespace changes
Inline
Side-by-side
Jenkinsfile
View file @
26a5d4e4
...
...
@@ -23,20 +23,33 @@ def sendReportEmail() {
if
(
cc
)
{
to
=
[
to
,
cc
].
findAll
{
it
}.
join
(
','
)
}
if
(!
fileExists
(
'reports/latest/email-summary.html'
))
{
writeFile
encoding:
'UTF-8'
,
file:
'reports/latest/email-summary.html'
,
text:
body
}
if
(!
fileExists
(
'reports/latest/email-subject.txt'
))
{
writeFile
encoding:
'UTF-8'
,
file:
'reports/latest/email-subject.txt'
,
text:
subject
+
'\n'
}
try
{
emailext
(
from:
'liguangyu@sinopharm.com'
,
replyTo:
'liguangyu@sinopharm.com'
,
to:
to
,
subject:
subject
,
body:
body
,
mimeType:
'text/html'
,
attachLog:
false
,
attachmentsPattern:
'reports/latest/email-summary.html,reports/latest/email-summary.txt'
)
echo
"已发送报告邮件至 ${to}(正文为摘要+报告链接,附件为 email-summary.html)"
def
credId
=
env
.
SMTP_CREDENTIALS_ID
?:
'sinopharm-smtp'
withCredentials
([
usernamePassword
(
credentialsId:
credId
,
usernameVariable:
'SMTP_USER'
,
passwordVariable:
'SMTP_PASS'
)
])
{
withEnv
([
"EMAIL_TO=${to}"
,
'SMTP_HOST=mail.sinopharm.com'
,
'SMTP_PORT=465'
,
'SMTP_FROM=liguangyu@sinopharm.com'
])
{
if
(
isUnix
())
{
sh
'python3 scripts/send-ci-email.py'
}
else
{
bat
'python scripts\\send-ci-email.py'
}
}
}
echo
"已发送报告邮件至 ${to}"
}
catch
(
err
)
{
echo
"邮件发送失败
。请安装 Email Extension 插件,并在 Manage Jenkins → System 配置 SMTP
:${err}"
echo
"邮件发送失败
(国药邮箱 SMTP LOGIN/465)
:${err}"
}
}
...
...
scripts/send-ci-email.py
0 → 100644
View file @
26a5d4e4
#!/usr/bin/env python3
"""Send the CI HTML summary through SMTP LOGIN/SSL. Used by Jenkins post."""
from
__future__
import
annotations
import
os
import
smtplib
import
ssl
import
sys
from
email.header
import
Header
from
email.mime.multipart
import
MIMEMultipart
from
email.mime.text
import
MIMEText
from
pathlib
import
Path
ROOT
=
Path
(
__file__
).
resolve
().
parents
[
1
]
LATEST
=
ROOT
/
"reports"
/
"latest"
def
env
(
name
:
str
,
default
:
str
=
""
)
->
str
:
return
os
.
environ
.
get
(
name
,
default
).
strip
()
def
main
()
->
int
:
to
=
env
(
"EMAIL_TO"
)
if
not
to
:
print
(
"[send-ci-email] EMAIL_TO 为空,跳过"
,
file
=
sys
.
stderr
)
return
2
user
=
env
(
"SMTP_USER"
)
password
=
env
(
"SMTP_PASS"
)
if
not
user
or
not
password
:
print
(
"[send-ci-email] 未配置 SMTP_USER/SMTP_PASS"
,
file
=
sys
.
stderr
)
return
2
host
=
env
(
"SMTP_HOST"
,
"mail.sinopharm.com"
)
port
=
int
(
env
(
"SMTP_PORT"
,
"465"
)
or
"465"
)
sender
=
env
(
"SMTP_FROM"
,
user
)
subject_file
=
LATEST
/
"email-subject.txt"
body_file
=
LATEST
/
"email-summary.html"
subject
=
env
(
"EMAIL_SUBJECT"
)
if
not
subject
and
subject_file
.
exists
():
subject
=
subject_file
.
read_text
(
encoding
=
"utf-8"
).
strip
()
if
not
subject
:
subject
=
"SPD UI 自动化测试报告"
if
body_file
.
exists
():
body
=
body_file
.
read_text
(
encoding
=
"utf-8"
)
else
:
body
=
env
(
"EMAIL_BODY"
)
or
"<p>未生成摘要,请打开 Jenkins 查看 Playwright 报告。</p>"
msg
=
MIMEMultipart
(
"alternative"
)
msg
[
"From"
]
=
sender
msg
[
"To"
]
=
to
msg
[
"Reply-To"
]
=
sender
msg
[
"Subject"
]
=
Header
(
subject
,
"utf-8"
)
msg
.
attach
(
MIMEText
(
body
,
"html"
,
"utf-8"
))
context
=
ssl
.
create_default_context
()
with
smtplib
.
SMTP_SSL
(
host
,
port
,
context
=
context
,
timeout
=
30
)
as
smtp
:
smtp
.
login
(
user
,
password
)
smtp
.
sendmail
(
sender
,
[
addr
.
strip
()
for
addr
in
to
.
split
(
","
)
if
addr
.
strip
()],
msg
.
as_string
())
print
(
f
"[send-ci-email] SENT_OK to
{
to
}
"
)
return
0
if
__name__
==
"__main__"
:
raise
SystemExit
(
main
())
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment