2018-11-12 13:18:57 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Ci
|
|
|
|
class DestroyPipelineService < BaseService
|
|
|
|
def execute(pipeline)
|
2018-11-13 11:27:00 -05:00
|
|
|
raise Gitlab::Access::AccessDeniedError unless can?(current_user, :destroy_pipeline, pipeline)
|
2018-11-12 13:18:57 -05:00
|
|
|
|
2019-04-12 15:29:47 -04:00
|
|
|
Ci::ExpirePipelineCacheService.new.execute(pipeline, delete: true)
|
2019-03-26 02:01:14 -04:00
|
|
|
|
2021-08-03 20:08:51 -04:00
|
|
|
pipeline.cancel_running if pipeline.cancelable?
|
2021-07-09 05:09:53 -04:00
|
|
|
|
2022-01-17 13:16:07 -05: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-12 19:16:12 -05:00
|
|
|
pipeline.reset.destroy!
|
2020-08-27 11:10:21 -04:00
|
|
|
|
|
|
|
ServiceResponse.success(message: 'Pipeline not found')
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
ServiceResponse.error(message: 'Pipeline not found')
|
2018-11-12 13:18:57 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|