Search code examples
azurepowershellazure-devopsazure-cli

Azure CLI - Automation account replace-content is breaking on new line


I've got a very frustrating situation using the Azure CLI and attempting to replace the content of an Automation Account.

I am attempting to update it via a Azure DevOps pipeline AzureCLI@2 task. This is the script line i am calling

az automation runbook replace-content --debug --automation-account-name "${{ parameters.automationAccountName }}" --resource-group "${{ parameters.resourceGroup }}" --name "Schedule Summary" --content "`@temp.txt"

The issue i am having is the automation account runbook is updated, but the text is truncated. The contents of temp.txt is this -

Param(
    [string]$resourceGroup ='',
    [string]$UAMI ='',
    [string]$serverInstance ='',

But the script that ends up in the runbook is simply

Param(

Its clearly breaking on CRLF but i can't figure out how to fix it. If i remove all CRLF then it appears as one line and the script then doesn't run.

I can tell where the problem is? Is the AzureCLI, powershell? or the devops task.


Solution

  • I run the script in windows hosted agent and reproduce your issue.Its clearly breaking on CRLF. Because windows can't identify the CRLF. You should run the script in Linux agent.

    breaking on CRLF based on windows agent RESULT

    alter to linux agent in pipeline

    pool:
      vmImage: ubuntu-22.04