maikvandergaag / msft-extensions

Repository for extensions mainly used for Azure DevOps Extensions
https://msftplayground.com
MIT License
126 stars 80 forks source link

File content to Variable: Files that include `r fails to convert to multiline variable #514

Closed petero-dk closed 4 months ago

petero-dk commented 7 months ago

Describe the issue A clear and concise description of what the issue is.

Extension

To Reproduce Steps to reproduce the behavior:

  1. Create a file that contains \r\n new lines (specifically the VSTS extension Generate Release Notes from Build does this)
  2. Load it into a variable
  3. See everything goes haywire

Expected behavior A variable that contains a nice multi line string

Situation (please complete the following information):

I managed to fix it by loading the file via a powershell script instead, the script looks like this.

# Read the contents of the file into a variable
$fileContent = Get-Content -Path "$(System.DefaultWorkingDirectory)/ReleaseNotes.md" -Raw

# Set the file content as a pipeline variable

$fileContent = $fileContent -replace "`r", ""
$fileContent = $fileContent -replace "`n", "%0D%0A"
Write-Host "##vso[task.setvariable variable=ReleaseNotes2]$fileContent"

# Print the file content (optional)
Write-Output "File Content: $fileContent"
Write-Output "Done"
maikvandergaag commented 5 months ago

@petero-dk: What was your configuration of the task?

github-actions[bot] commented 4 months ago

It looks like there hasn't been a reply in 30 days, so I'm closing this issue.