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

cancel_pipelines: include downstream pipelines

parent c8f97623
No related branches found
No related tags found
Loading
Pipeline #48166 passed with stage
in 18 minutes and 48 seconds
...@@ -8,6 +8,39 @@ from gitlab.v4.objects import Project, ProjectPipeline ...@@ -8,6 +8,39 @@ from gitlab.v4.objects import Project, ProjectPipeline
import common import common
def cancel_pipeline_including_children(
project: Project,
pipeline: ProjectPipeline,
):
"""Cancel pipeline including downstream pipelines (parent/child or multi-project).
Args:
project: Project containing the pipeline
pipeline: Pipeline to cancel
Returns:
Nothing
"""
# Browse through all downstream pipelines
for bridge in pipeline.bridges.list():
if not bridge.downstream_pipeline:
continue
# Check if downstream pipeline is in different project
if bridge.downstream_pipeline["project_id"] != pipeline.project_id:
project = pipeline.manager.gitlab.projects.get(
bridge.downstream_pipeline["project_id"]
)
# Recurse to downstream pipeline
downstream_pipeline = project.pipelines.get(bridge.downstream_pipeline["id"])
cancel_pipeline_including_children(project, downstream_pipeline)
pipeline.cancel()
def cancel_pipelines( def cancel_pipelines(
project: Project, project: Project,
ref: str = "", ref: str = "",
...@@ -31,7 +64,7 @@ def cancel_pipelines( ...@@ -31,7 +64,7 @@ def cancel_pipelines(
cancelled_pipelines = [] cancelled_pipelines = []
for pipeline in pipelines: for pipeline in pipelines:
if pipeline.id < below_pipeline_id: if pipeline.id < below_pipeline_id:
pipeline.cancel() cancel_pipeline_including_children(project, pipeline)
cancelled_pipelines.append(pipeline) cancelled_pipelines.append(pipeline)
return cancelled_pipelines return cancelled_pipelines
......
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