debian-mirror-gitlab/app/services/ci/play_build_service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

40 lines
1.1 KiB
Ruby
Raw Normal View History

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-09-04 01:27:46 +05:30
check_access!(build, job_variables_attributes)
2021-03-08 18:12:59 +05:30
2023-01-13 00:05:48 +05:30
if build.can_enqueue?
build.user = current_user
build.job_variables_attributes = job_variables_attributes || []
build.enqueue!
AfterRequeueJobService.new(project, current_user).execute(build)
build
2017-08-17 22:00:37 +05:30
else
2023-01-13 00:05:48 +05:30
retry_build(build)
2017-08-17 22:00:37 +05:30
end
2023-01-13 00:05:48 +05:30
rescue StateMachines::InvalidTransition
retry_build(build.reset)
2017-08-17 22:00:37 +05:30
end
2021-09-04 01:27:46 +05:30
private
2023-01-13 00:05:48 +05:30
def retry_build(build)
Ci::RetryJobService.new(project, current_user).execute(build)[:job]
end
2021-09-04 01:27:46 +05:30
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-08-17 22:00:37 +05:30
end
end
2021-09-04 01:27:46 +05:30
Ci::PlayBuildService.prepend_mod_with('Ci::PlayBuildService')