EMail Body目前正在研究 ADO 发布管道。第一个作业是手动干预作业,其中通知用户通过评论批准/拒绝部署。下一阶段发送电子邮件通知,其中包含用户提供的评论和其他详细信息。我的问题是,如果评论是多行的,除了第一行,其他行不会显示在电子邮件通知中。以下是我使用 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
将变量注释值分配给 release-scope 并在下面的发送电子邮件任务中使用它
发送电子邮件任务
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 行。
答案 0 :(得分:0)
多行注释未显示在来自 ADO 发布管道中手动干预作业的电子邮件通知中
那是因为该变量不支持值中的多行。
当您通过日志命令设置评论和批准状态的变量时:
const char*
它只将第一行设置为变量Write-Host "##vso[task.setvariable variable=release-scope]$comment"
Write-Host "##vso[task.setvariable variable=approval-status;]$status"
。这就是电子邮件通知中只有第 1 行的原因。
您可以在管道中添加一个命令行任务来输出 release-scope
的值。
要解决此问题,我们可以使用 powershell 任务将 release-scope
替换为 \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
。
如果您想在电子邮件通知中坚持换行格式,您需要在 powershell 任务中使用脚本而不是电子邮件任务发送电子邮件。
您可以查看文档 Send-MailMessage 以了解更多详细信息。