Skip to content

Lint .gitlab-ci.yaml

Local only linters

These don't use the /api/v4/ci/lint API endpoint

check-jsonschema

see ../../json.md

- repo: https://github.com/python-jsonschema/check-jsonschema
  rev: 0.33.0
  hooks:
    - id: check-gitlab-ci
      args: ["--verbose"]

Linters that use the Gitlab API

These use the /api/v4/ci/lint API endpoint. One major blocker: CI Lint API support for passing included files in working tree is still open, until this gets solved we can't use the Gitlab CI API with local includes. See also pre-commit check_yaml hook fails on gitlab-ci files for more details.

orobardet/gitlab-ci-linter

  • GitHub
  • Go
  • Can be used with pre-commit
  • Not available in Arch-/AUR, Mise, Mason
  • Install from Gitlab releases
  • pre-commit-hook integration
  • Setup
    • Not available as Arch/AUR package, install from GitHub releases

Usage:

gitlab-ci-lint

pre-commit-gitlabci-lint

  • GitHub
  • Last commit 2024-01
  • Can deal with includes
  • No Arch/Mise package

Install:

pipx install pre-commit-gitlabci-lint

Setup:

  1. Create an access token with api scope.
  2. Set access token value in an environment variable named GITLAB_TOKEN or GITLABCI_LINT_TOKEN.
  3. Add the projectId for your gitlab project as a command line argument, or set it in the config file.
  4. Adjust the configuration in ~/.config/.gitlabci-lint/config.toml

Usage:

gitlabci-lint -p <project_id>

pre-commit:

repos:
  - repo: https://github.com/bjd2385/pre-commit-gitlabci-lint
    rev: v1.4.0
    hooks:
      - id: gitlabci-lint
      # args: [-b, 'https://custom.gitlab.host.com', '-p', '12345678']

Stale / not working