{"id":15923890,"url":"https://github.com/parithosh/gitlab-ci-yaml-validator","last_synced_at":"2026-01-16T04:58:39.645Z","repository":{"id":105041176,"uuid":"256476950","full_name":"parithosh/gitlab-ci-yaml-validator","owner":"parithosh","description":"To validate the .gitlab-ci.yml files before committing changes","archived":false,"fork":false,"pushed_at":"2020-04-17T11:05:41.000Z","size":4,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-09T02:14:48.005Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/parithosh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-17T10:50:46.000Z","updated_at":"2020-04-17T11:05:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"ce9cab6d-01d0-4d13-b3f9-f7b1d0661de1","html_url":"https://github.com/parithosh/gitlab-ci-yaml-validator","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parithosh%2Fgitlab-ci-yaml-validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parithosh%2Fgitlab-ci-yaml-validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parithosh%2Fgitlab-ci-yaml-validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parithosh%2Fgitlab-ci-yaml-validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/parithosh","download_url":"https://codeload.github.com/parithosh/gitlab-ci-yaml-validator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247005397,"owners_count":20868019,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-06T21:03:01.539Z","updated_at":"2026-01-16T04:58:39.636Z","avatar_url":"https://github.com/parithosh.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# gitlab-ci-yaml-validator\n\nOne might want to validate changes made to a .gitlab-ci.yml file before commiting changes. This could be to avoid seeing the pipeline error or just to have\na sanity check while making changes. \n\nLuckily gitlab offers an api-endpoint to enable this, found [here] (https://docs.gitlab.com/ee/api/lint.html). We can create a curl request to this \napi endpoint to check the file. Since a lot of us work on the terminal, we can create a function automate this. \n\n# Setup\n\nI've used/tested it using iterm2 with oh-my-zsh. Python and the js-yaml-cli npm package is needed.\n\n# Instructions\n\n1. Install the npm package with ```npm install -g js-yaml-cli```\n\n2. Open your ```.zshrc``` file with your text editor, most probably in ~/.zshrc \n\n3. Append the following function to the file\n\n```\nfunction gitlab-yaml-lint() {\n    curl --header \"Content-Type: application/json\" https://gitlab.com/api/v4/ci/lint --data \"{\\\"content\\\": $(cat $1 | yaml2json | tr -d '\\n' | python -c 'import json,sys; print(json.dumps(sys.stdin.read()))')}\"\n}\n```\n\n4. Restart the shell with ```source ~/.zshrc```\n\n5. Test it with ```gitlab-yaml-lint .gitlab-ci.yml``` while in the same folder as the .gitlab-ci.yml file\n\n# FAQ\n\n1. Does this work with custom Gitlab installations? Yes, just change the curl URL to your custom installation URL\n\n2. How do I test .gitlab-ci.yml files that depend on private repositories (if include commands are used,etc)? You can create and add an API token to the \ncurl request with ```--header \"PRIVATE-TOKEN: ***\"```\n\n3. Can I avoid using python and yaml2json? Yes, the gitlab api just expects json (its a bit picky with formatting). As long as you can provide it the \njson content in the right format, it will work. One could potentially use tools such as ```jq``` or ```yq``` to achieve this\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparithosh%2Fgitlab-ci-yaml-validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fparithosh%2Fgitlab-ci-yaml-validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparithosh%2Fgitlab-ci-yaml-validator/lists"}