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.
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?
I found this Add comments to .gitlab-ci.yml, which was merged two years ago. Now I just need to find the page that says how to do it!
https://docs.gitlab.com/ee/development/code_comments.html - not helpful
https://docs.gitlab.com/ee/development/cicd/templates.html#template-types -
https://docs.gitlab.com/ee/development/cicd/templates.html#explain-the-template-with-comments - Looks like the answer so why does it complain?
https://blog.wplauncher.com/add-comments-to-yaml-file/#:~:text=In%20order%20to%20add%20comments,line%20in%20a%20YAML%20file. This says the #
is the way to do comments.
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.
In order to add comments to a YAML file, you simply have to use the # (hashtag symbol) at the start of the line. For example, below is an example of one commented line in a YAML file.
YAML does not support block or multi-line comments. In order to create a multi-line comment, we need to suffix each line with a # . # block comments.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With