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
|
|
|
|
2021-10-18 11:12:11 -04:00
|
|
|
# Ci::Pipeline#destroy triggers `use_fast_destroy :job_artifacts` and
|
|
|
|
# ci_builds has ON DELETE CASCADE to ci_pipelines. The pipeline, the builds,
|
|
|
|
# job and pipeline artifacts all get destroyed here.
|
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
|