Created
February 13, 2019 15:50
-
-
Save AndrewOfC/ec3fe93aead024b9ba4cd0bc4ab42862 to your computer and use it in GitHub Desktop.
Q&D python for command line to validate .gitlab-ci.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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