0

EMail BodyCurrently working on a ADO release Pipeline. 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. My issue is, if the comments are multi-lined, apart from the first line, other lines does not show up in email notification. Below is my setup using powershell and Send email task

Powershell setup -

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

Send email Task

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

Line 2

Then it prints only Line 1 in the email notification.

Olaf
  • 4,690
  • 2
  • 15
  • 23
  • `$comment -replace '\r?\n', '
    '` ?
    – Theo Dec 31 '20 at 11:25
  • Hi, Can you elaborate on your answer please. – saikumar reddy Dec 31 '20 at 11:56
  • You are obviously sending an email in HTML format, so replace the newlines in the $comment into HTML newlines (`
    `). Otherwise, newlines will be normalized in HTML
    – Theo Dec 31 '20 at 12:32
  • Did you mean changing this
    Documentation URLs / Comments : $(release-scope) ? If so it is still showing only the 1st line

    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)
    – saikumar reddy Dec 31 '20 at 12:48

1 Answers1

0

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

That because the variable does not support multi-line in the 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. That the reason why only Line 1 in the email notification.

You could add a command line task in the pipeline to output the value of release-scope.

To resolve this issue, we could use powershell task to replace the \n with , to remove the wrap:

$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:

testline1, testline2

instead of only 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.

You could check the document Send-MailMessage for some more details.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135