gitlab-ci

How do I add comments to .gitlab-ci.yaml file?


I tried commenting out some lines from a .gitlab-ci.yml file and the pipeline is failing saying the YAML is not properly formatted.

Below is the picture of what I see in the GitLab CI-Pipeline UI.

enter image description here

Below is the .gitlab-ci.yml file that is error.

stages:
  - build
  - test
#  - release

build-demo-commands:
    extends: .npm-job
    stage: build
    script:
        - npm run build-demo-prod

include:
  - project: 'myproj/gitlab-ci'
    ref: '1.2.0'
    file: 'templates/npm.gitlab-ci.yml'
#  - project: 'myproj/gitlab-ci'
#    ref: '1.2.0'
#    file: 'templates/Kaniko-npm.gitlab-ci.yml'

I suspect that there is a pre-processor for the CI-pipeline which supports a comment syntax.

What is the correct way to comment out lines in a .gitlab-ci.yml file?

Searching for answer

EDIT/UPDATE:

I believe the problem is with the included scripts and not with adding the comments. When I removed the comments I still got an error. The error was:

Found errors in your .gitlab-ci.yml:
npm-deploy-snapshot job: chosen stage does not exist; available stages are .pre
build
test
.post
You can also test your .gitlab-ci.yml in CI Lint

So I now believe that using the hash (#) character is the correct way to comment a .gitlab-ci.yml file.


Solution

  • Comments in YAML use a # character which comments out the remainder of the line

    Wikipedia says:

    Comments begin with the number sign (#), can start anywhere on a line and continue until the end of the line. Comments must be separated from other tokens by whitespace characters.[16] If # characters appear inside of a string, then they are number sign (#) literals.