Created
March 27, 2018 11:03
-
-
Save SamyCoenen/2523adddecaa92bfff22266199bb5ce4 to your computer and use it in GitHub Desktop.
Trigger Gitlab pipeline if it's not already running
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
import requests | |
from subprocess import call | |
params = (('status', 'running'),) | |
params2 = (('status', 'pending'),) | |
headers = {'PRIVATE-TOKEN': '$TOKEN'} | |
url = 'https://gitlab.com/api/v4/projects/......................./pipelines' | |
r = requests.get(url, params=params,headers=headers) | |
print r.text | |
r2 = requests.get(url, params=params2,headers=headers) | |
print r2.text | |
if len(r.text) < 3 and len(r2.text) < 3: | |
print "nothing running" | |
call(["curl", "--request","POST","--form","token=$PIPELINETOKEN","--form","ref=master","https://gitlab.com/api/v3/projects/2807925/trigger/builds"]) | |
elif len(r.text)>3: | |
print "running" | |
if len(r2.text)>3: | |
print "pending" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment