2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
module Ci
|
|
|
|
class PlayBuildService < ::BaseService
|
2019-10-12 21:52:04 +05:30
|
|
|
def execute(build, job_variables_attributes = nil)
|
2021-01-03 14:25:43 +05:30
|
|
|
raise Gitlab::Access::AccessDeniedError unless can?(current_user, :play_job, build)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
if job_variables_attributes.present? && !can?(current_user, :set_pipeline_variables, project)
|
|
|
|
raise Gitlab::Access::AccessDeniedError
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
# Try to enqueue the build, otherwise create a duplicate.
|
|
|
|
#
|
|
|
|
if build.enqueue
|
2021-04-29 21:17:54 +05:30
|
|
|
build.tap do |build|
|
|
|
|
build.update(user: current_user, job_variables_attributes: job_variables_attributes || [])
|
|
|
|
|
|
|
|
next unless ::Feature.enabled?(:ci_fix_pipeline_status_for_dag_needs_manual, project, default_enabled: :yaml)
|
|
|
|
|
|
|
|
AfterRequeueJobService.new(project, current_user).execute(build)
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
else
|
|
|
|
Ci::Build.retry(build, current_user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|