发布工件作为电子邮件附件发送给用户组

Release Artifacts delivered to user group as an attachment in email

我在 VSTS 中使用构建和发布。我在我的构建定义中使用复制文件选项,并将工件复制到一个文件夹中。我希望在发布结束时创建的工件(.exe、.dll、.zip 等)必须附在电子邮件中,并且必须发送到电子邮件地址列表。 如何实现。

可以使用Send Email任务来实现。详情如下:

在你的发布环境的最后->添加发送邮件任务->配置需要的选项。

要通过“发送电子邮件”任务传送工件文件,您可以select“添加附件”选项并指定附件的绝对路径:

使用存档任务压缩文件并使用下面给出的 powershell 脚本发送带附件的电子邮件。

现在使用 Powershell 任务并粘贴以下脚本。请编辑 SMTP 和电子邮件设置。

$SMTPServer = "smtp.gmail.com"
$SMTPPort = "587"
$Username = "Youremail@gmail.com"
$Password = "Pass@1"
$to = "senderemail@gmail.com"
#$cc = "ccemail@gmail.com"
# Below subject line will have todays date and Build status as Succeed or Failed
$subject = "$(get-date -format dd-mm-yy) Automation Test report $(Agent.JobStatus)"
$body = "Your email body text"
# Enter the path of existing Archieve output folder
$attachment = "$(Build.ArtifactStagingDirectory)/YourZipFolderName.zip"
$message = New-Object System.Net.Mail.MailMessage
$message.subject = $subject
$message.IsBodyHTML = $true
$message.body = $body
$message.to.add($to)
#$message.cc.add($cc)
$message.from = $username
$message.attachments.add($attachment)
$smtp = New-Object System.Net.Mail.SmtpClient($SMTPServer, $SMTPPort);
$smtp.EnableSSL = $true
$smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);
$smtp.send($message)
write-host "Mail Sent successfully using GMAIL"

请确保使用 运行 选项作为“即使之前的任务失败,除非构建被取消”,如下所示。