Azure DevOps – Tips and Tricks – 7 – Resolve the “While scanning a literal block scalar, found extra spaces in first line” error.

In this article, we are going to learn how to fix an error with the message “While scanning a literal block scalar, found extra spaces in first line”.

Scenario

Recently, we have noticed that ALL our YAML pipelines which has either script / bash tasks in shortcut syntax (an example below) have started failing with the error message “While scanning a literal block scalar, found extra spaces in first line”. The sample screenshot is shown below for your reference.

Azure DevOps – Tips and Tricks – 7 – Resolve the While scanning a literal block scalar, found extra spaces in first line
Advertisements

As shown below, the pipeline has just one script task (shortcut syntax). The script task’s first line is empty with two spaces (you can see two periods. Each period denotes a space)

Azure DevOps – Tips and Tricks – 7 – Resolve the While scanning a literal block scalar, found extra spaces in first line – Empty Line

Usually, the YAML editor show in-line errors if there are any syntax errors. However, in this case, the error is only shown when you try to run the Pipeline as shown in the above screen shot.

Solution

In order to solve this, we can follow the below two simple solutions.

Advertisements

Option1 – Remove the empty line

After removing the empty line, I was able to run the pipeline without any errors. As shown in the below screenshot, the pipeline get queues and runs successfully.

Azure DevOps – Tips and Tricks – 7 – Resolve the While scanning a literal block scalar, found extra spaces in first line – Job Queued

Option2 – Use Regular Syntax (instead of shortcut syntax)

In the above screenshots, I showed you the error for Script tasks. ADO Pipeline was also throwing an error for Bash scripts as well.

Advertisements

Let’s me use Bash Task using regular syntax for this Option to solve the error.

As shown in the below screenshot, use regular task and ensure there are no unnecessary spaces in the script (from line 20 to 22).

Azure DevOps – Tips and Tricks – 7 – Resolve the While scanning a literal block scalar, found extra spaces in first line – Solution 2

Note: We have hundreds of Pipelines with this additional line with few spaces. It was working fine since years. However, it started failing since a few days.

We are fixing this in all the pipelines one after the other. If you have also faced this issue and if you have a better solution that the ones specified on this article, please feel free to provide your feedback in the comment sections.

Advertisements

Thanks for reading the blog. Hope it helped.

Do you like this article? If you want to get more updates about these kind of articles, you can join my Learning Groups

WhatsApp

Telegram

Advertisements
Advertisements
Advertisements

One comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s