Skip to content

Instantly share code, notes, and snippets.

@SamyCoenen
Created March 27, 2018 11:03
Show Gist options
  • Save SamyCoenen/2523adddecaa92bfff22266199bb5ce4 to your computer and use it in GitHub Desktop.
Save SamyCoenen/2523adddecaa92bfff22266199bb5ce4 to your computer and use it in GitHub Desktop.
Trigger Gitlab pipeline if it's not already running
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