Home > Blockchain >  when using powershell inline script in Yaml file I get error "while parsing a block mapping did
when using powershell inline script in Yaml file I get error "while parsing a block mapping did

Time:06-09

Yaml is really frustrating to work with, I exported as YAML from an azure devops release pipleine and each time i insert this code into my yaml file and run it Azure devops always says "error -while parsing a block mapping did not find expected key" . Is someone able to help on how to include inline powershell scripts in yaml as the export yaml option in Azure Devops is useless

 - task: AzurePowerShell@5
   displayName: 'test inline script in yaml'
   inputs:
   azureSubscription: 'azuresubscriptionid'
   ScriptType: InlineScript
   Inline: |
     # Setting Variables
     $var1 = "1!
     Write-Output $var1
   preferredAzurePowerShellVersion: 3.1.0

CodePudding user response:

Please find below the correct script:

  - task: AzurePowerShell@5
    displayName: 'test inline script in yaml'
    inputs:
      azureSubscription: 'azuresubscriptionid'
      ScriptType: InlineScript
      Inline: |
        # Setting Variables
        $var1 = "1"
        Write-Output $var1
      preferredAzurePowerShellVersion: 3.1.0

There is an additional indent after inputs:

Please have a look at the enter image description here

Thanks to @vince-bowdren regarding the typo in the script.

  • Related