From 756860feb1bc23aa6d6628d09a9d62a86d80160f Mon Sep 17 00:00:00 2001 From: Guillaume Pasero <guillaume.pasero@c-s.fr> Date: Mon, 15 Apr 2019 12:12:06 +0200 Subject: [PATCH] CI: script to cancel twin pipelines --- CI/check_twin_pipelines.py | 45 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 CI/check_twin_pipelines.py diff --git a/CI/check_twin_pipelines.py b/CI/check_twin_pipelines.py new file mode 100644 index 0000000000..13c08db29f --- /dev/null +++ b/CI/check_twin_pipelines.py @@ -0,0 +1,45 @@ +# +# Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) +# +# This file is part of Orfeo Toolbox +# +# https://www.orfeo-toolbox.org/ +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import os +import urllib.request +import urllib.parse +import json + +""" +Check for any duplicated twin pipeline and cancel it +""" +if __name__ == "__main__": + env = os.environ + sha1 = env['CI_COMMIT_SHA'] + if 'CI_MERGE_REQUEST_IID' in env.keys(): + gitlab_url = "https://gitlab.orfeo-toolbox.org/api/v4/projects/" + gitlab_url+= env['CI_PROJECT_ID'] + '/pipelines?sha='+sha1 + gitlab_request = urllib.request.Request(gitlab_url) + gitlab_request.add_header('PRIVATE-TOKEN' , env['K8S_SECRET_TWIN_PIPELINE'] ) + res = urllib.request.urlopen(gitlab_request).read().decode() + jres = json.loads(res) + for item in jres: + if item["id"] < int(env['CI_PIPELINE_ID']) and item["status"] == "running": + gitlab_url = "https://gitlab.orfeo-toolbox.org/api/v4/projects/" + gitlab_url+= env['CI_PROJECT_ID'] + '/pipelines/'+str(item["id"])+'/cancel' + gitlab_request = urllib.request.Request(gitlab_url) + gitlab_request.add_header('PRIVATE-TOKEN' , env['K8S_SECRET_TWIN_PIPELINE'] ) + res2 = urllib.request.urlopen(gitlab_request).read().decode() -- GitLab