如果您想发送电子邮件,则可以直接将其添加到管道中。
配置系统:
转到管理 Jenkins-> 配置系统。在此处向下滚动到电子邮件通知部分。如果您使用的是 Gmail,则为 SMTP 服务器键入 smtp.gmail.com。单击高级并选择使用 SMTP 身份验证。输入您的 Gmail 用户名和密码。选择使用 SSL 选项并输入端口号为 465。单击应用,然后单击保存。
创建 Jenkins 管道作业:
pipeline {
agent any
stages {
stage("Send Email")
{
steps {
emailext body: 'your body', subject: 'your sububject', to: 'abc@gmail.co,'
}
}
}
}
以上方法是一个示例,向您展示如何通过管道发送电子邮件。
执行您的应用程序,然后发送电子邮件:
pipeline {
agent any
stages {
stage("App execution")
{
steps {
// Execute your app
bat label: 'Execute your app', script:"yourapp.bat >log.txt "
}
}
stage("Send Email")
{
steps {
emailext body: 'your body', subject: 'your sububject', to: 'abc@gmail.co,'
}
}
}
}
根据条件发送电子邮件
pipeline {
agent any
stages {
stage("App execution")
{
steps {
// Execute your app
bat label: 'Execute your app', script:"yourapp.bat >log.txt "
}
}
stage("Send Email")
{
steps {
// You can add condition based on your log file in previous step :
// Example : please change below code as per your logic
// if log contains "Email" then only send email
if(log.contains(" Email:")){
emailext body: 'your body', subject: 'your subject', to: 'abc@gmail.co,'
}
}
}
}
}