Skip to content

Instantly share code, notes, and snippets.

@AndrewOfC
Created February 13, 2019 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndrewOfC/ec3fe93aead024b9ba4cd0bc4ab42862 to your computer and use it in GitHub Desktop.
Save AndrewOfC/ec3fe93aead024b9ba4cd0bc4ab42862 to your computer and use it in GitHub Desktop.
Q&D python for command line to validate .gitlab-ci.yml
#! /usr/bin/python
#
# script to validate .gitlab-ci.yml
#
import sys
import requests
import json
def main():
r = requests.post("https://gitlab.example.com/api/v4/ci/lint", json={ 'content': file(sys.argv[1], 'r').read() })
if r.status_code != requests.codes['OK']:
sys.exit(3)
data = r.json()
if data['status'] != 'valid':
for e in data['errors']:
print >> sys.stderr, e
sys.exit(1)
sys.exit(0) # valid
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment