'.gitlab-ci.yml Syntax Error

I'm working with the following .gitlab-ci.yml config:

image: node:latest

stages: 
  - build
  - test

build:
  stage: build
  script:
    - npm install

 test:
   stage: test
   script:
     - ./testing/test.js

When pushing to GitLab, i get a 'Your pipeline as failed' error and when i look at what failed, its a yaml error:

Status: syntax is incorrect 

Error: (<unknown>): did not find expected key while parsing a block mapping 
at line 1 column 1

As far as i can see, the image: node:latest is correct. Any help with this would be great.



Solution 1:[1]

The problem is the indentation of you test job. That problem is making your whole yml to break therefore raising the error on line 1. Just remove the excessive whitespaces like the code below and it will be fine.

image: node:latest

stages: 
  - build
  - test

build:
  stage: build
  script:
    - npm install

test:
 stage: test
 script:
   - ./testing/test.js

Note that in YAML the indentation is used to denote the structure. So it is important to pay attention to it.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 alejdg