I had a problem recently where I was writing a lot of GitLab CI configuration without autocomplete. Now, of course, eventually you get a decent handle on the syntax, but I figured it'd be a lot nicer if PhpStorm actually gave me some hints.
That is when I found out you can add custom JSON Schema definitions to Jetbrains IDEs to allow for extended validation (and autocomplete!) on any of your files. All you need is the JSON Schema for whatever configuration you're writing, which most companies will publish. Oddly, the settings pane you use to configure this seems to be undocumented for all of Jetbrains' IDEs at the time of publishing.
I wanted autocomplete on .gitlab-ci.yml
, so I went looking if GitLab published their own JSON Schema for their CI/CD
config, and thankfully they do. So I did the
following:
- Found the URL of the JSON Schema definition file (raw version) GitLab publishes.
- Opened
Preferences | Languages & Frameworks | Schemas and DTDs | JSON Schema Mappings
in PhpStorm. - Added a new JSON Schema Mapping called
GitLab CI
with the raw URL from above and the correct schema version selected (see root$schema
property in the GitLab-published JSON Schema for what version the document is). - Added a new file path pattern for
*.gitlab-ci.yml
, so the validation/autocomplete is active on files that match that pattern.
When you now edit a file that matches the configured file pattern (.gitlab-ci.yml
, in this case), you should have
autocomplete for your GitLab CI/CD configuration!
... Of course, I later found out you can also click the little "Globe" icon next to the "Schema file or URL" input to quickly load commonly-used JSON Schemas, one of which is GitLab's CI/CD. So do that instead!
And, for what it's worth, all JSON Schemas hosted on and maintained by JSON Schema Store are automatically available in all Jetbrains IDEs. So if you're following conventions, you should already have autocomplete for over 700 file types!