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

Time:12-15

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.

CodePudding user response:

I've tried in my environment by adding Devops CLI extension in Azure bash and it worked for me successfully with the same parameters as yours.

I created a PS file in Az cloud itself and saved with the .ps1 extension as set the runbook type to PowerShell and updated the script as follows:

az automation runbook replace-content --content "@runbook.ps1" --automation-account-name "xxxxautomation" --name "xxxxrunbook" --resource-group "xxxxRG"

vi runbook.ps1:

enter image description here

Content replacement done in runbook:

enter image description here

If still the issue persists: In Azure DevOps, call a webhook with parameters and then start a runbook that imports the Azure DevOps runbooks.

But when you are dealing with Azure DevOps, I suggest you create or update runbooks via RESULT

  • Related