2018-07-16 12:31:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-12 05:46:24 -04:00
|
|
|
module Ci
|
|
|
|
class PlayBuildService < ::BaseService
|
2019-07-29 03:43:10 -04:00
|
|
|
def execute(build, job_variables_attributes = nil)
|
2021-05-20 02:10:43 -04:00
|
|
|
check_access!(build, job_variables_attributes)
|
2021-01-14 07:10:54 -05:00
|
|
|
|
2017-05-03 06:32:39 -04:00
|
|
|
# Try to enqueue the build, otherwise create a duplicate.
|
2017-04-12 05:46:24 -04:00
|
|
|
#
|
|
|
|
if build.enqueue
|
2021-04-02 11:09:19 -04:00
|
|
|
build.tap do |build|
|
2021-12-02 19:11:20 -05:00
|
|
|
build.update!(user: current_user, job_variables_attributes: job_variables_attributes || [])
|
2021-04-02 11:09:19 -04:00
|
|
|
|
|
|
|
AfterRequeueJobService.new(project, current_user).execute(build)
|
|
|
|
end
|
2017-04-12 05:46:24 -04:00
|
|
|
else
|
2022-03-23 14:08:47 -04:00
|
|
|
Ci::RetryJobService.new(project, current_user).execute(build)[:job]
|
2017-04-12 05:46:24 -04:00
|
|
|
end
|
|
|
|
end
|
2021-05-20 02:10:43 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def check_access!(build, job_variables_attributes)
|
|
|
|
raise Gitlab::Access::AccessDeniedError unless can?(current_user, :play_job, build)
|
|
|
|
|
|
|
|
if job_variables_attributes.present? && !can?(current_user, :set_pipeline_variables, project)
|
|
|
|
raise Gitlab::Access::AccessDeniedError
|
|
|
|
end
|
|
|
|
end
|
2017-04-12 05:46:24 -04:00
|
|
|
end
|
|
|
|
end
|
2021-05-20 02:10:43 -04:00
|
|
|
|
|
|
|
Ci::PlayBuildService.prepend_mod_with('Ci::PlayBuildService')
|