Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

when using powershell inline script in Yaml file I get error "while parsing a block mapping did not find expected key"

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

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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 documentation.

Online Validator

enter image description here

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading