Skip to content
Snippets Groups Projects
Commit 1d88c920 authored by Guillaume Pasero's avatar Guillaume Pasero
Browse files

CI: can't make the data option to work properly, find an other way

parent 55a36ab1
No related branches found
No related tags found
No related merge requests found
...@@ -29,16 +29,14 @@ import time ...@@ -29,16 +29,14 @@ import time
Send a request to Gitlab and return the answer Send a request to Gitlab and return the answer
The request parameter is added after `project/:id/` The request parameter is added after `project/:id/`
""" """
def GitlabRequest(request, project=53,data={}, token=''): def GitlabRequest(request, project=53, token=''):
gitlab_url = "https://gitlab.orfeo-toolbox.org/api/v4/projects/" gitlab_url = "https://gitlab.orfeo-toolbox.org/api/v4/projects/"
gitlab_url+= str(project) + '/' + request gitlab_url+= str(project) + '/' + request
params = None myHeader = {}
if data:
params = urllib.parse.urlencode(data).encode('ascii')
gitlab_request = urllib.request.Request(gitlab_url)
if token: if token:
gitlab_request.add_header('PRIVATE-TOKEN' , token ) myHeader = {'PRIVATE-TOKEN':token}
res = urllib.request.urlopen(gitlab_request, data=params) gitlab_request = urllib.request.Request(gitlab_url,headers=myHeader)
res = urllib.request.urlopen(gitlab_request)
return json.loads(res.read().decode()) return json.loads(res.read().decode())
""" """
...@@ -76,7 +74,7 @@ if __name__ == "__main__": ...@@ -76,7 +74,7 @@ if __name__ == "__main__":
sys.exit(1) sys.exit(1)
else: else:
# No: cancel any previous "normal" pipeline on the same SHA1 # No: cancel any previous "normal" pipeline on the same SHA1
jres = GitlabRequest('pipelines', project=env['CI_PROJECT_ID'], data={'sha':sha1}, token=env['K8S_SECRET_TWIN_PIPELINE']) jres = GitlabRequest('pipelines?sha='+sha1, project=env['CI_PROJECT_ID'], token=env['K8S_SECRET_TWIN_PIPELINE'])
for item in jres: for item in jres:
if item["id"] < int(env['CI_PIPELINE_ID']) and item["status"] == "running": if item["id"] < int(env['CI_PIPELINE_ID']) and item["status"] == "running":
print("Cancel pipeline "+str(item["id"])) print("Cancel pipeline "+str(item["id"]))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment