2018-11-12 18:18:57 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Ci
|
|
|
|
class DestroyPipelineService < BaseService
|
|
|
|
def execute(pipeline)
|
2018-11-13 16:27:00 +00:00
|
|
|
raise Gitlab::Access::AccessDeniedError unless can?(current_user, :destroy_pipeline, pipeline)
|
2018-11-12 18:18:57 +00:00
|
|
|
|
2019-04-12 19:29:47 +00:00
|
|
|
Ci::ExpirePipelineCacheService.new.execute(pipeline, delete: true)
|
2019-03-26 06:01:14 +00:00
|
|
|
|
2022-07-25 12:09:06 +00:00
|
|
|
pipeline.cancel_running(cascade_to_children: true, execute_async: false) if pipeline.cancelable?
|
2021-07-09 09:09:53 +00:00
|
|
|
|
2022-01-17 18:16:07 +00:00
|
|
|
# The pipeline, the builds, job and pipeline artifacts all get destroyed here.
|
|
|
|
# Ci::Pipeline#destroy triggers fast destroy on job_artifacts and
|
|
|
|
# build_trace_chunks to remove the records and data stored in object storage.
|
|
|
|
# ci_builds records are deleted using ON DELETE CASCADE from ci_pipelines
|
|
|
|
#
|
2022-01-13 00:16:12 +00:00
|
|
|
pipeline.reset.destroy!
|
2020-08-27 15:10:21 +00:00
|
|
|
|
|
|
|
ServiceResponse.success(message: 'Pipeline not found')
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
ServiceResponse.error(message: 'Pipeline not found')
|
2018-11-12 18:18:57 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|