Skip to content
Versora

Manual

Pipelines

Validating the .gitlab-ci.yml

7 min read

On this page

An error in the .gitlab-ci.yml usually only shows up after the push: the pipeline isn't even created, or it fails to read the configuration. Versora checks the CI file before:

  • before the commit, when the CI file, or a file it includes with include: local, is staged;
  • before the push, when any pushed commit changes the CI file;
  • when you ask, on the Validate CI screen, which shows the problems, the jobs by stage and the merged YAML, and simulates the pipeline on a branch.

With the remote on a registered GitLab, GitLab itself validates the file, through the project's lint API. Without a server, without a token or with GitLab down, Versora checks only the YAML syntax, and says so clearly.

The CI file is the .gitlab-ci.yml at the root, or the one the project configured in GitLab.

Before the commit and the push

How it works

  1. When you commit with the CI file staged (or one of its local includes), the bar shows "Validating the CI…". On push, "Validating the CI before pushing…".
  2. If GitLab finds nothing, a short notice appears: ".gitlab-ci.yml validated on GitLab: no errors.", with the Details button, which opens the Validate CI screen with the result.
  3. Without a server, the notice is ".gitlab-ci.yml YAML syntax is OK, but GitLab didn't validate it." and the reason, also with Details.
  4. If there are problems, they go into the common Before committing or Before pushing dialog, in the "CI validation (.gitlab-ci.yml)" group (on push, "CI validation (.gitlab-ci.yml on feature/login)"). Each error appears as ".gitlab-ci.yml:12 — message". Commit anyway or Push anyway goes ahead; Cancel goes back.

Errors appear as serious problems; warnings, as warnings. When only the syntax was checked, the list gets the item "Only the YAML syntax was checked: GitLab didn't validate this file", with the reason.

The validation before the commit waits for GitLab for up to 6 seconds. If it takes longer, the syntax check counts, and the answer, when it arrives, is kept for the next validation: "GitLab didn't answer within 6 seconds. When the answer arrives, it's kept for the next validation."

A validation that fails for any other reason never blocks the commit or the push.

The Validate CI screen

Where to find it

  • Palette (Ctrl+P): "Validate CI (.gitlab-ci.yml)" (detail: "Checks the pipeline configuration on GitLab — or only the YAML syntax, without a server").
  • The CI file's menu (right-click the .gitlab-ci.yml in the changes list, in the staging area or in a commit's files) › Validate CI…. After a validation, the item also appears on the files it includes.
  • The Details button of the validation notice.
  • Preferences › CI validation › Validate CI now…

Step by step

  1. Open Validate CI. The title shows the validated file.
  2. In Version to validate, choose which version of the file to check:
    • File on disk: as it is now in the working directory;
    • Staged: the staged version;
    • HEAD: the one from the latest commit;
    • Commit 1a2b3c4d or Branch feature/login: when the screen was opened from a commit or a branch.
  3. To see how the pipeline would be created on a branch, check Simulate the pipeline (dry run) and fill in the Branch or tag for the simulation (it comes filled in with the branch of the current branch's upstream). The simulation "evaluates workflow and rules as a real push would, without creating anything". Enter in the field validates again.
  4. The summary shows the result and who validated it.
  5. Use the tabs to see the details. Validate again repeats the validation.
  6. Close (or Close (Esc)) goes back to the app.

The summary

SummaryWhen
"Valid configuration"GitLab found nothing
"Valid, with 2 warnings"only warnings
"3 errors in the configuration"GitLab found errors
"YAML syntax is OK"only the syntax was checked and it's correct
"2 YAML syntax errors"only the syntax was checked and it has errors

Below, the context lines:

  • "Validated by GitLab 19.4 on gitlab.exemplo.com (equipe/app)." and how long it took;
  • "Pipeline simulation on branch main.";
  • "The include: local files were read from branch main on the server, not from your repository." (with the commit, when the server reports it);
  • "Result kept from a recent validation with the same content.";
  • when only the syntax was checked: "Only the YAML syntax was checked:" and the reason, with the Git servers… button when the problem is with the token or the registration.

The tabs

TabWhat it shows
ProblemsErrors and warnings, with the origin ("GitLab" or "local check") and the location ("file:line"). Clicking the location shows the line in the file ("Show line 18 of .gitlab-ci.yml"). It also lists the Includes: the type (local, URL, other project, template, component, "with a variable (can't be resolved here)"), "with rules", "doesn't exist in this version", "in .gitlab-ci.yml:4", "No file matches the wildcard." and "differs from the server: GitLab used its own version". With nothing: "No problems found."
JobsThe jobs by stage, as GitLab put them together: "allowed to fail", "environment: production", "tags: docker", "needs: build", and the script ("Script (4 lines)"). Without a server: "The job list and the merged YAML come from GitLab: they show up when the validation runs on the server."
Merged YAMLThe configuration after resolving the include, extends and anchors, as GitLab sees it.
FileThe validated file, with the problem lines marked.

Local includes

GitLab reads the include: local files from the branch on the server, not from your repository. If an included file is different here, Versora warns you and checks the syntax of your version:

  • "GitLab validated using the server's version (branch main) of: ci/test.yml. The local versions, which are different, only had their YAML syntax checked.";
  • a problem GitLab points out in that file comes with "— this is about the server's version (branch main); the local version is different and only had its syntax checked.";
  • "The local include "ci/test.yml" (in .gitlab-ci.yml) doesn't exist in this version: the pipeline will fail to read the configuration." (with rules, "… It has rules: it only fails when it's included.").

Without a server: only the YAML syntax

Without a registered GitLab, without a token, with GitLab down or slow, Versora checks the YAML syntax of the file and of the local includes. The messages explain the error and how to fix it, for example:

  • "Tab in indentation: YAML only accepts spaces for indenting."
  • "Missing ": " after the key."
  • "Double quote opened here and never closed."
  • "Misplaced list item ("- "): after "key:", start the list on the next line."
  • "The alias "*padrao" has no anchor "&padrao" defined before it."
  • "The key "script" appears more than once in the same mapping: GitLab keeps only the last one."
  • ".gitlab-ci.yml is empty: GitLab requires a configuration."
  • ".gitlab-ci.yml must be a mapping of keys (jobs, stages, variables…), not a text or a list."

What Versora does

  • On the server: POST /projects/:id/ci/lint (GitLab 13.6 or later), with the content of the chosen version. With the simulation, the lint runs as a push to the given branch (dry run). The token needs the api scope and the Developer role or higher in the project.
  • Local: the YAML syntax analysis done by Versora itself, without running anything from the repository.
  • The result for the same content is kept for a few minutes, so the call isn't repeated.

How to undo

The validation changes nothing in the repository or on the server. The simulation (dry run) doesn't create a pipeline.

Caveats and messages

  • "There's no token for gitlab.exemplo.com. Add one in Git servers ("api" scope) to validate on GitLab."
  • "The token can't validate the CI of equipe/app: the API requires permission to create pipelines (Developer or higher)."
  • "GitLab 13.4 on gitlab.exemplo.com doesn't have project CI validation (POST /projects/:id/ci/lint, available from 13.6)."
  • "The remote is on GitHub, which doesn't use .gitlab-ci.yml." and "The remote isn't a GitLab server."
  • "There's no way to tell whether gitlab.exemplo.com is a GitLab server. Add it in Git servers, with its type and a token, to validate on the server."
  • "The GitLab project uses ci/pipeline.yml as its CI file, not .gitlab-ci.yml.": the screen validates the file configured in the project.
  • "GitLab stopped the validation because it took too long: the result may be incomplete."
  • ".gitlab-ci.yml is too large for the local syntax check."
  • "Couldn't validate": the screen shows the error and leaves Validate again.

Preferences › CI validation (palette: "CI validation preferences"):

OptionWhat it doesDefault
Validate before committing"When the CI file, or a file it includes with include: local, is staged."on
Validate before pushing"When a pushed commit changes the CI file: validates the version at the tip of the branch."on

The page also has the How it works box, the Validate CI now… button and Restore defaults. There's no company policy key for CI validation.

See also