gpt4 book ai didi

jenkins - 使用 Groovy Postbuild 操作从 Jenkins 作业发送电子邮件

转载 作者:行者123 更新时间:2023-12-04 03:11:53 27 4
gpt4 key购买 nike

有没有办法使用 Groovy Postbuild action 从 Jenkins 工作发送电子邮件? ?类似于如何使用 Jenkins 管道插件来完成

 mail to: 'devops@acme.com',
subject: "Job '${env.JOB_NAME}' (${env.BUILD_NUMBER}) is waiting for input",
body: "Please go to ${env.BUILD_URL}."

最佳答案

感谢 https://stackoverflow.com/a/37194996/4624905我发现我可以直接使用 JavaMail API。它帮助了我。

import javax.mail.*
import javax.mail.internet.*


def sendMail(host, sender, receivers, subject, text) {
Properties props = System.getProperties()
props.put("mail.smtp.host", host)
Session session = Session.getDefaultInstance(props, null)

MimeMessage message = new MimeMessage(session)
message.setFrom(new InternetAddress(sender))
receivers.split(',').each {
message.addRecipient(Message.RecipientType.TO, new InternetAddress(it))
}
message.setSubject(subject)
message.setText(text)

println 'Sending mail to ' + receivers + '.'
Transport.send(message)
println 'Mail sent.'
}
Usage Example:

sendMail('mailhost', messageSender, messageReceivers, messageSubject, messageAllText)

关于jenkins - 使用 Groovy Postbuild 操作从 Jenkins 作业发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44493385/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com