Skip to content
Snippets Groups Projects
Commit 84eb6e22 authored by Tim Jaacks's avatar Tim Jaacks
Browse files

Revert "Cancel all pipelines on newer commit"

This reverts commit f7582b74.
parent f7582b74
No related branches found
No related tags found
1 merge request!356Cancel all pipelines on newer commit
...@@ -125,22 +125,12 @@ cancel-previous-pipelines: ...@@ -125,22 +125,12 @@ cancel-previous-pipelines:
- if: $CI_MERGE_REQUEST_IID - if: $CI_MERGE_REQUEST_IID
allow_failure: true allow_failure: true
script: 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-ci/scripts/cancel_pipelines.py
--gitlab-url=${CI_SERVER_URL} --gitlab-url=${CI_SERVER_URL}
--token=${GITBOT_TOKEN} --token=${GITBOT_TOKEN}
--project=${CI_PROJECT_PATH} --project=${CI_PROJECT_PATH}
--ref=${CI_MERGE_REQUEST_REF_PATH} --ref=${CI_MERGE_REQUEST_REF_PATH}
--below-pipeline-id=${CI_PIPELINE_ID} --below-pipeline-id=${CI_PIPELINE_ID}
--status created
--status scheduled
--status pending
--status preparing
--status running
--status canceled
yamllint: yamllint:
extends: .yamllint extends: .yamllint
......
...@@ -44,15 +44,13 @@ def cancel_pipeline_including_children( ...@@ -44,15 +44,13 @@ def cancel_pipeline_including_children(
def cancel_pipelines( def cancel_pipelines(
project: Project, project: Project,
ref: str = "", ref: str = "",
status: str = "running",
below_pipeline_id: int = sys.maxsize, below_pipeline_id: int = sys.maxsize,
) -> list[ProjectPipeline]: ) -> list[ProjectPipeline]:
"""Cancel Gitlab pipelines. """Cancel currently running pipelines.
Args: Args:
project: GitLab project the pipeline belongs to project: GitLab project the pipeline belongs to
ref: Git ref (branch or tag) the pipeline is running on 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 below_pipeline_id: cancel only pipelines with ID below this
Returns: Returns:
...@@ -60,7 +58,7 @@ def cancel_pipelines( ...@@ -60,7 +58,7 @@ def cancel_pipelines(
""" """
pipelines = project.pipelines.list( 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 = [] cancelled_pipelines = []
...@@ -98,13 +96,6 @@ def main(): ...@@ -98,13 +96,6 @@ def main():
dest="ref", dest="ref",
default="", default="",
) )
parser.add_argument(
"--status",
help="""Status the pipeline has""",
dest="status",
action="append",
required=True,
)
parser.add_argument( parser.add_argument(
"--below-pipeline-id", "--below-pipeline-id",
help="""Cancel only pipelines with IDs lower than this""", help="""Cancel only pipelines with IDs lower than this""",
...@@ -118,23 +109,20 @@ def main(): ...@@ -118,23 +109,20 @@ def main():
gitlab = Gitlab(args.gitlab_url, private_token=args.token) gitlab = Gitlab(args.gitlab_url, private_token=args.token)
project = common.get_project(gitlab, args.project) project = common.get_project(gitlab, args.project)
for status in args.status: print(
print( f"Searching for pipelines in project '{args.project}' on ref '{args.ref}' "
f"Searching for pipelines in project '{args.project}' on ref '{args.ref}' " f"with IDs below {args.below_pipeline_id}"
f"with IDs below {args.below_pipeline_id} and status {status}" )
)
cancelled_pipelines = cancel_pipelines( cancelled_pipelines = cancel_pipelines(project, args.ref, args.below_pipeline_id)
project, args.ref, status, args.below_pipeline_id
)
if not cancelled_pipelines: if not cancelled_pipelines:
print("No pipelines found.") print("No running pipelines found.")
continue sys.exit(0)
print("Cancelled pipelines:") print("Cancelled pipelines:")
for pipeline in cancelled_pipelines: for pipeline in cancelled_pipelines:
print(pipeline.web_url) print(pipeline.web_url)
if __name__ == "__main__": if __name__ == "__main__":
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment