简体   繁体   English

来自 ADO 发布管道中的手动干预作业的 Email 通知中未显示多行注释

[英]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.

相关问题 在 Azuredevops 发布管道中使用 powershell 脚本执行 SSIS 作业 - Executing SSIS job using powershell script in Azuredevops release pipeline 如何从变量获取和设置 ADO 管道 Powershell 中的数组? - how to get and set array inside the ADO pipeline Powershell from variable? 在Azure DevOps中的Release管道中的作业代理的两个任务之间共享PowerShell变量 - Share PowerShell variable between two tasks of the job agent in Release pipeline in Azure DevOps 使用Powershell无需手动干预即可安装任何exe - Installing any exe without having manual intervention using powershell 如何阻止 azure-devops 发布管道失败 - How to stop azure-devops release-pipeline from failing 无法在 Azure 发布管道中使用从上一步传递的变量 - Unable to utilise variable passed from previous step in a Azure release pipeline 从 Azure DevOps Release Pipeline 调用控制台应用程序 - Calling console application from Azure DevOps Release Pipeline Azure DevOps:如何从 Release Pipeline 中的 PowerShell 脚本构建 Azure Pipeline 检索构建工件? - Azure DevOps: How to retrieve a build artifact from build Azure Pipeline from a PowerShell Script in Release Pipeline? TFS 2017发布管道 - TFS 2017 Release pipeline 在PowerShell中将状态从子作业传递到父作业 - Pass status from child job up to a parent job in PowerShell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM