[英]Send email notification from Jenkins
I want to send email notification when any job gets done.我想在任何工作完成时发送电子邮件通知。 Please let me know how can we propagate.
请让我知道我们如何传播。
You can configure Jenkins to send email when a job finishes either by using a plugin or not.您可以将 Jenkins 配置为在作业完成时发送电子邮件,无论是否使用插件。
First you have to configure your mail server settings by clicking on Manage Jenkins > Configure System
and find the E-mail Notification
section near the bottom of the page.首先,您必须通过单击“
Manage Jenkins > Configure System
来配置您的邮件服务器设置,然后在页面底部附近找到“ E-mail Notification
部分。 Optionally also configure System Admin e-mail address
in the Jenkins Location
section.也可以选择在
Jenkins Location
部分配置System Admin e-mail address
。
Then for each job got to its configuration and Add post-build action
, select E-mail Notification
and configure as needed.然后对于每个作业进行其配置并
Add post-build action
,选择E-mail Notification
并根据需要进行配置。
The issue with default jenkins email mechanism is that it has very limited customization.默认 jenkins 电子邮件机制的问题在于它的自定义非常有限。
The alternate approach is to use the Email-Ext plugin , a powerful email notification mechanism.另一种方法是使用Email-Ext 插件,这是一种强大的电子邮件通知机制。 You can define some global triggers but you can also customize the settings for each job.
您可以定义一些全局触发器,但也可以自定义每个作业的设置。 Sending emails for success, failure or any other build status is supported.
支持发送成功、失败或任何其他构建状态的电子邮件。
Go to : manage jenkins --> manage plugins --> 'available' tab --> select 'email extension plugin' --> click on button 'install without restart'转到:管理 jenkins --> 管理插件 --> “可用”选项卡 --> 选择“电子邮件扩展插件” --> 单击按钮“无需重启即可安装”
manage jenkins --> configure system --> enter details in 'email notification'管理 jenkins --> 配置系统 --> 在“电子邮件通知”中输入详细信息
Fill up the details as given below and save it:填写下面给出的详细信息并保存:
有一个Jenkins email-ext插件可以添加触发器和收件人。
This answer is for sending mail using python script & outlook through Jenkins.此答案用于通过 Jenkins 使用 python 脚本和 Outlook 发送邮件。
You need to have PsExec.exe for this.为此,您需要拥有 PsExec.exe。 This runs the applications remotely.
这将远程运行应用程序。
create a freestyle project & in that run following dos shell command:创建一个自由式项目 & 在该运行中遵循 dos shell 命令:
path\\to\\psexec.exe -u username -p password -i 1 cmd -accepteula /c python path\\to\\SendMail.py path\\to\\psexec.exe -u 用户名 -p 密码 -i 1 cmd -accepteula /c python path\\to\\SendMail.py
Username & password is for the windows user account where outlook runs.用户名和密码用于运行 Outlook 的 Windows 用户帐户。 path\\to\\SendMail.py is the location of the python script.
path\\to\\SendMail.py 是 python 脚本的位置。 SendMail.py kinda looks like this:
SendMail.py 有点像这样:
import win32com.client as win32
outlook=win32.Dispatch('outlook.application')
mail=outlook.CreateItem(0)
mail.To='abc@xyz.com'
mail.Subject="Test Mail"
mail.HTMLBody="Hiii, This is just a test mail."
mail.Send()
Here I'm using wind32com for executing outlook.这里我使用wind32com 来执行outlook。 The mail will be sent using the default account logged in outlook.
邮件将使用登录 Outlook 的默认帐户发送。
You can trigger to build this project everytime after a job completes.每次作业完成后,您都可以触发构建此项目。
Hope this is of any help to anyone :)希望这对任何人都有帮助:)
All the above answers are about plug-in and its usage but not how to use it in pipeline execution.以上所有答案都是关于插件及其用法,而不是如何在管道执行中使用它。 Assuming smtp server is configured in jenkins and https://plugins.jenkins.io/email-ext/ plug-in is installed , we can write or use the plug-in ij the below format.
假设在jenkins中配置了smtp服务器并安装了https://plugins.jenkins.io/email-ext/插件,我们可以编写或使用插件ij如下格式。
def csproj_path = 'dotnetcore_sample.csproj'
pipeline {
agent{
node {
label 'dotnet-31'
}
}
stages {
stage ('build locally'){
steps{
sh "dotnet build ${csproj_path}"
}
}
stage ('Prompt check'){
steps {
mail to: 'bruce.wayne@gmail.com',
cc : 'clark.kent@gamil.com'
subject: "INPUT: Build ${env.JOB_NAME}",
body: "Awaiting for your input ${env.JOB_NAME} build no: ${env.BUILD_NUMBER} .Click below to promote to production\n${env.JENKINS_URL}job/${env.JOB_NAME}\n\nView the log at:\n ${env.BUILD_URL}\n\nBlue Ocean:\n${env.RUN_DISPLAY_URL}"
timeout(time: 60, unit: 'MINUTES'){
input message: "Promote to Production?", ok: "Promote"
}
}
}
}
post {
failure {
mail to: 'mymail@gmail.com',
cc : 'ccedpeople@gamil.com'
subject: "FAILED: Build ${env.JOB_NAME}",
body: "Build failed ${env.JOB_NAME} build no: ${env.BUILD_NUMBER}.\n\nView the log at:\n ${env.BUILD_URL}\n\nBlue Ocean:\n${env.RUN_DISPLAY_URL}"
}
success{
mail to: 'mymail@gmail.com',
cc : 'ccedpeople@gamil.com'
subject: "SUCCESSFUL: Build ${env.JOB_NAME}",
body: "Build Successful ${env.JOB_NAME} build no: ${env.BUILD_NUMBER}\n\nView the log at:\n ${env.BUILD_URL}\n\nBlue Ocean:\n${env.RUN_DISPLAY_URL}"
}
aborted{
mail to: 'mymail@gmail.com',
cc : 'ccedpeople@gamil.com'
subject: "ABORTED: Build ${env.JOB_NAME}",
body: "Build was aborted ${env.JOB_NAME} build no: ${env.BUILD_NUMBER}\n\nView the log at:\n ${env.BUILD_URL}\n\nBlue Ocean:\n${env.RUN_DISPLAY_URL}"
}
}
}
The above declarative pipeline consists of below features上述声明性管道由以下功能组成
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.