Skip to content

Instantly share code, notes, and snippets.

@Betree
Created August 19, 2017 05:30
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Betree/56f9669c3adb2a1633429ff321198fff to your computer and use it in GitHub Desktop.
Save Betree/56f9669c3adb2a1633429ff321198fff to your computer and use it in GitHub Desktop.
Verify Gitlab CI config (.gitlab-ci.yml) using command line

Test your CI config upon Gitlab.com API

You need to install js-yaml-cli first :

npm install -g js-yaml-cli

Example :

> ./check_gitlab_ci.sh
{"status":"invalid","errors":["variables config should be a hash of key value pairs"]}%  
#!/usr/bin/env bash
CONTENT=$(cat .gitlab-ci.yml | yaml2json | tr -d '\n' | python -c 'import json,sys; print(json.dumps(sys.stdin.read()))')
curl --header "Content-Type: application/json" https://gitlab.com/api/v4/ci/lint --data "{\"content\": $CONTENT}"
@GabLeRoux
Copy link

Nice, thanks for this. I had some troubles with yaml2json and since I don't like gists, I made a repo inspired by this gist and dockerized it so it's easy to use in a ci:

https://github.com/gableroux/ansible-docker-image

✌️

@Code0x58
Copy link

Or you could use https://github.com/Code0x58/gitlab-ci-validate (no additional dependencies) - I'll give it some polish at some point, but it does the trick at the moment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment