2

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
1
  • 2
    You know you've got a missing end-quote on the line where you define $var1? That's not what's causing your current error, but you'll be wanting to fix it next. Commented Jun 8, 2022 at 13:46

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

5 Comments

i just tried that and same error
@itye1970 Please check it online here: jsonformatter.org/yaml-validator/743d9f
@vince-bowdren I fixed the mentioned typo in script
ok it passes validation but when it runs i get Input required: ConnectedServiceNameARM
ok sorted its working!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.