From 84eb6e22684cf2878dbb4a8e78b8a3ad448a1f21 Mon Sep 17 00:00:00 2001 From: Tim Jaacks <tim.jaacks@seco.com> Date: Thu, 19 Oct 2023 11:54:53 +0200 Subject: [PATCH] Revert "Cancel all pipelines on newer commit" This reverts commit f7582b74e7c565d55bb8a0315fe75c4ab4385fa2. --- manifest-integration.yml | 10 ---------- scripts/cancel_pipelines.py | 38 +++++++++++++------------------------ 2 files changed, 13 insertions(+), 35 deletions(-) diff --git a/manifest-integration.yml b/manifest-integration.yml index 52ced288..c91e175b 100644 --- a/manifest-integration.yml +++ b/manifest-integration.yml @@ -125,22 +125,12 @@ cancel-previous-pipelines: - if: $CI_MERGE_REQUEST_IID allow_failure: true script: - # Cancel pipelines in all states up to and including "running". - # Also cancel canceled pipelines, because Gitlab might have already canceled them - # without canceling their child pipelines. See Gitlab issue: - # https://gitlab.com/gitlab-org/gitlab/-/issues/390453 - .gitlab-ci/scripts/cancel_pipelines.py --gitlab-url=${CI_SERVER_URL} --token=${GITBOT_TOKEN} --project=${CI_PROJECT_PATH} --ref=${CI_MERGE_REQUEST_REF_PATH} --below-pipeline-id=${CI_PIPELINE_ID} - --status created - --status scheduled - --status pending - --status preparing - --status running - --status canceled yamllint: extends: .yamllint diff --git a/scripts/cancel_pipelines.py b/scripts/cancel_pipelines.py index f4fed2b6..acea143e 100755 --- a/scripts/cancel_pipelines.py +++ b/scripts/cancel_pipelines.py @@ -44,15 +44,13 @@ def cancel_pipeline_including_children( def cancel_pipelines( project: Project, ref: str = "", - status: str = "running", below_pipeline_id: int = sys.maxsize, ) -> list[ProjectPipeline]: - """Cancel Gitlab pipelines. + """Cancel currently running pipelines. Args: project: GitLab project the pipeline belongs to ref: Git ref (branch or tag) the pipeline is running on - status: status the pipeline has below_pipeline_id: cancel only pipelines with ID below this Returns: @@ -60,7 +58,7 @@ def cancel_pipelines( """ pipelines = project.pipelines.list( - ref=ref, status=status, as_list=False, retry_transient_errors=True + ref=ref, status="running", as_list=False, retry_transient_errors=True ) cancelled_pipelines = [] @@ -98,13 +96,6 @@ def main(): dest="ref", default="", ) - parser.add_argument( - "--status", - help="""Status the pipeline has""", - dest="status", - action="append", - required=True, - ) parser.add_argument( "--below-pipeline-id", help="""Cancel only pipelines with IDs lower than this""", @@ -118,23 +109,20 @@ def main(): gitlab = Gitlab(args.gitlab_url, private_token=args.token) project = common.get_project(gitlab, args.project) - for status in args.status: - print( - f"Searching for pipelines in project '{args.project}' on ref '{args.ref}' " - f"with IDs below {args.below_pipeline_id} and status {status}" - ) + print( + f"Searching for pipelines in project '{args.project}' on ref '{args.ref}' " + f"with IDs below {args.below_pipeline_id}" + ) - cancelled_pipelines = cancel_pipelines( - project, args.ref, status, args.below_pipeline_id - ) + cancelled_pipelines = cancel_pipelines(project, args.ref, args.below_pipeline_id) - if not cancelled_pipelines: - print("No pipelines found.") - continue + if not cancelled_pipelines: + print("No running pipelines found.") + sys.exit(0) - print("Cancelled pipelines:") - for pipeline in cancelled_pipelines: - print(pipeline.web_url) + print("Cancelled pipelines:") + for pipeline in cancelled_pipelines: + print(pipeline.web_url) if __name__ == "__main__": -- GitLab