I have been a user of GitLab CI for a long time. I use it to check my own code before deploying and to manage deployment and building for most of the applications that I use. I use Yaml a lot, in fact, I am not sure that there are many people in DevOps that do not use Yaml a lot, it is pretty omnipotent inside modern tools.
I am always trying to find ways to make my code more readable and therefore running linters over my code is a great way to do that. Yamllint is a super way of being able to lint yaml.
The process is pretty simple. If you are using the default configurations, you can just use the yamllint Docker container and away you go!
yamllint: image: sdesbure/yamllint script: - yamllint .
There are a number of small differences between the YAML configuration of lots of files and Yamllint gives a fairly easy way of managing this. You can put it directly into the
yamllint command, however, I much prefer using
.yamllint from the project root to get consistent linting.
You can look at the .yamllint file inside GitLab CE to see the file in action, but what you can see is that it is really simple:
--- extends: default rules: line-length: disable document-start: disable
Basically, there were so many files that did not have valid linting on
document-start I decided to disable these rules, however, everything else went ahead!
.yamllintto GitLab CE (and EE)
This then took us to making sure that Yamllint was a part of GitLab in the future. Basically speaking, this is used in two areas, firstly for the GitLab CI templates that are embedded to the project, secondly to GitLab CI itself, when they dogfood the GitLab CI system.
From the root
.gitlab-ci.yml file you can see that it includes a large set of other GitLab CI files:
include: - ... - local: .gitlab/ci/yaml.gitlab-ci.yml - ...
This links to a separate
# Yamllint of *.yml for .gitlab-ci.yml. # This uses rules from project root `.yamllint`. lint-ci-gitlab: extends: - .default-tags - .default-retry - .default-only only: changes: - "**/*.yml" image: sdesbure/yamllint:latest dependencies:  script: - yamllint .gitlab-ci.yml .gitlab/ci lib/gitlab/ci/templates changelogs
And that is it. Successfully integrated Yamllint with GitLab to do any YAML files with ease.