Commit b45403ec authored by Guillaume Pasero's avatar Guillaume Pasero
Browse files

CI: difference between POST and GET requests

No related merge requests found
Showing with 9 additions and 4 deletions
+9 -4
......@@ -28,14 +28,19 @@ import time
"""
Send a request to Gitlab and return the answer
The request parameter is added after `project/:id/`
WARNING: when data is given, the request will be a POST
Otherwise, it is a GET
"""
def GitlabRequest(request, project=53, token=''):
def GitlabRequest(request, project=53, data=None, token=''):
gitlab_url = "https://gitlab.orfeo-toolbox.org/api/v4/projects/"
gitlab_url+= str(project) + '/' + request
params = None
myHeader = {}
if not data is None:
params = urllib.parse.urlencode(data).encode('ascii')
if token:
myHeader = {'PRIVATE-TOKEN':token}
gitlab_request = urllib.request.Request(gitlab_url,headers=myHeader)
gitlab_request = urllib.request.Request(gitlab_url, data=params, headers=myHeader)
res = urllib.request.urlopen(gitlab_request)
return json.loads(res.read().decode())
......@@ -67,7 +72,7 @@ if __name__ == "__main__":
if wip_regex.search(mrInfo["title"]):
# Yes: cancel the current pipeline
print("Cancel current pipeline "+env['CI_PIPELINE_ID'])
GitlabRequest('pipelines/'+env['CI_PIPELINE_ID']+'/cancel', \
GitlabRequest('pipelines/'+env['CI_PIPELINE_ID']+'/cancel', data={}, \
project=env['CI_PROJECT_ID'], token=env['K8S_SECRET_TWIN_PIPELINE'])
time.sleep(180)
print("Error: this pipeline should have been canceled")
......@@ -78,6 +83,6 @@ if __name__ == "__main__":
for item in jres:
if item["id"] < int(env['CI_PIPELINE_ID']) and item["status"] == "running":
print("Cancel pipeline "+str(item["id"]))
jres2 = GitlabRequest('pipelines/'+str(item["id"])+'/cancel', \
jres2 = GitlabRequest('pipelines/'+str(item["id"])+'/cancel', data={}, \
project=env['CI_PROJECT_ID'], token=env['K8S_SECRET_TWIN_PIPELINE'])
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment