skip to Main Content

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.

2

Answers


  1. 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 API instead of PowerShell modules which is efficient.

    Login or Signup to reply.
  2. 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
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search