[英]Mutli line comments is not showing up in Email notification from the Manual intervention job in ADO Release Pipeline
EMail Body Currently working on a ADO release Pipeline. EMail Body目前正在开发 ADO 发布管道。 The First job is a Manual Intervention Job, where a user is notified to approve/Reject the deployment with a comment.
第一个作业是手动干预作业,通知用户通过评论批准/拒绝部署。 The next stage sends out an email notification with the user provided comment and other details.
下一阶段发送 email 通知,其中包含用户提供的评论和其他详细信息。 My issue is, if the comments are multi-lined, apart from the first line, other lines does not show up in email notification.
我的问题是,如果评论是多行的,除了第一行,email 通知中不会显示其他行。 Below is my setup using powershell and Send email task
下面是我使用 powershell 和发送 email 任务的设置
Powershell setup - 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
Assigning variable comment value to release-scope and using it below in the send email task将变量注释值分配给发布范围并在下面的发送 email 任务中使用它
Send email Task发送 email 任务
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
Line 1 1号线
Line 2 2号线
Then it prints only Line 1 in the email notification.然后它只打印 email 通知中的第 1 行。
Mutli line comments is not showing up in Email notification from the Manual intervention job in ADO Release Pipeline
来自 ADO 发布管道中的手动干预作业的 Email 通知中未显示多行注释
That because the variable does not support multi-line in the value .那是因为该变量不支持 value 中的多行。
When you setup variables for comments and Approval status by logging command:当您通过记录命令设置评论和批准状态的变量时:
Write-Host "##vso[task.setvariable variable=release-scope]$comment"
Write-Host "##vso[task.setvariable variable=approval-status;]$status"
It only set the first line to the variable release-scope
.它仅将第一行设置为变量
release-scope
。 That the reason why only Line 1 in the email notification.这就是为什么 email 通知中只有 Line 1 的原因。
You could add a command line task in the pipeline to output the value of release-scope
.您可以将管道中的命令行任务添加到 output 的值
release-scope
。
To resolve this issue, we could use powershell task to replace the \n
with ,
to remove the wrap:要解决此问题,我们可以使用 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 "
Now, we could get the value release-scope
of is:现在,我们可以得到 is 的值
release-scope
:
testline1, testline2
instead of only testline1
.而不仅仅是
testline1
。
If you want to stick to the newline format in your email notification, you need send the e-mail in the powershell task with scripts instead of email task.如果您想在 email 通知中坚持使用换行符格式,您需要在 powershell 任务中使用脚本而不是 email 任务发送电子邮件。
You could check the document Send-MailMessage for some more details.您可以查看文档Send-MailMessage了解更多详细信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.