Azure DevOps, Scrum, & .NET Software Leadership and Consulting Services

Free course! Predicting the Future, Estimating, and Running Your Projects with Flow Metrics

YAML error in azure-pipelines.yml: “Bad indentation of a mapping entry”


Love it or hate it, you’ve got to admit that YAML build pipeline scripts can be a brittle. One little bit of whitespace out of place and — boom! — you staring at a ton of errors. I ran into two related errors yesterday while I was working on an Azure DevOps pipeline script: “bad indentation of a mapping entry” and “can not read an implicit mapping pair; a colon is missed”.

Azure DevOps Pipeline YAML errors

Here’s the YAML that was causing the problem:

              - task: AzureAppServiceSettings@1
                inputs:
                  azureSubscription: 'connection-to-yaml-test'
                  appName: 'bdcyaml'
                  resourceGroupName: 'rg-yamltest'
                  appSettings: |
                  [{ "name": "MiscSettings__BuildVersionMessage", "value": "$(Build.DefinitionName) - $(Build.BuildNumber)","slotSetting": true }, { "name": "ConnectionStrings__default", "value": "$(connectionstring-prod)", "slotSetting": true }]

I’m just about 100% certain that that preformatted YAML text isn’t going to format correctly in a browser and it’s going to be hard to read and see what’s going. It’s not a whole lot easier when you’re reading it in Visual Studio Code either.

The problematic YAML in Visual Studio Code

What’s happening? What’s the fix?

Well, I’m using the pipe symbol ‘|’ to deal with a long string value. In YAML, the pipe operator indicates a string literal which can optionally span multiple lines.

It’s subtle but I somehow lost a single space character ‘ ‘ before the value. If you use the YAML pipe ‘|’ to indicate a literal string, each line of that value needs to be indented by one space under the value that you’re setting. In my case, I’m passing a string value to the “appSettings:” property but the value is at the same indentation level as the property declaration.

The solution? Add a space to the start of the value line

The solution is easy. Just add a space.

I hope this helped.

-Ben

— Looking for help with your Azure DevOps build and release pipelines? Trying to wrap your head around YAML? Tricky continuous integration or continuous deployment (CI/CD) builds got you down? We can help. Drop us a line at info@benday.com.

SUBSCRIBE TO THE BLOG


2 responses to “YAML error in azure-pipelines.yml: “Bad indentation of a mapping entry””

  1. […] I wrote a post about an error I was getting in an Azure DevOps YAML Pipeline script. The gist was that I had a long string in the YAML file and I was running into a problem using the […]

  2. Steven Avatar
    Steven

    “If you use the YAML pipe ‘|’ to indicate a literal string, each line of that value needs to be indented by one space under the value that you’re setting. ”

    That is a tricky little thing – thanks for taking the time to write about it!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.