ADO 发布管道中手动干预作业的电子邮件通知中未显示多行注释

Mutli line comments is not showing up in Email notification from the Manual intervention job in ADO Release Pipeline

EMail Body目前正在处理 ADO 发布管道。第一项工作是手动干预工作,通知用户 approve/Reject 部署并发表评论。下一阶段发送电子邮件通知,其中包含用户提供的评论和其他详细信息。我的问题是,如果评论是多行的,除了第一行,其他行不会显示在电子邮件通知中。下面是我使用 powershell 和发送电子邮件任务的设置

Powershell 设置 -

dir
$B64Pat = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(":$(MY_PAT)"))
$url = "$(System.TeamFoundationServerUri)/$(System.TeamProject)/_apis/Release/releases/$(Release.ReleaseId)/manualinterventions?api-version=6.0"
$header = @{ Authorization = "Basic $B64Pat" }
$release = Invoke-RestMethod -Uri $url -Method Get -ContentType application/json -Headers $header
write-host $release.value.comments
$comment = $release.value.comments
write-host "$comment"
$status = $release.value.status

**Setup variables for comments and Approval status**
Write-Host "##vso[task.setvariable variable=release-scope]$comment"
Write-Host "##vso[task.setvariable variable=approval-status;]$status"

Write-Host $comment

Write-Host $release.value

正在将变量注释值分配给发布范围并在下面的发送电子邮件任务中使用它

发送电子邮件任务

Email-Body - in between <p></p> <h2></h2>

Hi Team,

This email is to notify that team has reviewed deployment request and provided their go/no-go decision. Please find details below.

Release Information:

BSA Approval Status : $(approval-status)

Documentation URLs / Comments : $(release-scope)

Here $(release-scope) are the comments provided by user in Manual intervention job. If the comments are like below

第 1 行

第 2 行

然后它只打印电子邮件通知中的第 1 行。

Mutli line comments is not showing up in Email notification from the Manual intervention job in ADO Release Pipeline

那是因为变量值不支持多行.

当您通过日志命令为评论和批准状态设置变量时:

Write-Host "##vso[task.setvariable variable=release-scope]$comment"
Write-Host "##vso[task.setvariable variable=approval-status;]$status"

仅将第一行设置为变量release-scope。这就是为什么电子邮件通知中只有第 1 行的原因。

您可以在管道中添加命令行任务以输出 release-scope 的值。

要解决此问题,我们可以使用 powershell 任务将 \n 替换为 , 以删除包装:

$NewComment = $comment  -replace "`n",", " -replace "`r",", "

write-host "this is NewComment $NewComment "

#**Setup variables for comments and Approval status**
Write-Host "##vso[task.setvariable variable=release-scope]$NewComment "

现在,我们可以得到 release-scope 的值是:

testline1, testline2

而不只是 testline1.

如果您想在电子邮件通知中坚持使用换行格式,您需要使用脚本而不是电子邮件任务在 powershell 任务中发送电子邮件。

您可以查看文档 Send-MailMessage 了解更多详情。