debian-mirror-gitlab/lib/gitlab/ci/pipeline/chain/build.rb

60 lines
2 KiB
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
module Gitlab
module Ci
module Pipeline
module Chain
class Build < Chain::Base
2021-03-08 18:12:59 +05:30
include Gitlab::Allowable
include Chain::Helpers
2018-03-17 18:26:18 +05:30
def perform!
@pipeline.assign_attributes(
source: @command.source,
project: @command.project,
ref: @command.ref,
sha: @command.sha,
before_sha: @command.before_sha,
2019-07-07 11:18:12 +05:30
source_sha: @command.source_sha,
target_sha: @command.target_sha,
2018-03-17 18:26:18 +05:30
tag: @command.tag_exists?,
trigger_requests: Array(@command.trigger_request),
user: @command.current_user,
pipeline_schedule: @command.schedule,
2019-02-15 15:39:39 +05:30
merge_request: @command.merge_request,
2019-12-04 20:38:33 +05:30
external_pull_request: @command.external_pull_request,
2021-03-11 19:13:27 +05:30
locked: @command.project.default_pipeline_lock,
2021-03-08 18:12:59 +05:30
variables_attributes: variables_attributes
2018-03-17 18:26:18 +05:30
)
end
def break?
2021-03-08 18:12:59 +05:30
@pipeline.errors.any?
end
private
def variables_attributes
variables = Array(@command.variables_attributes)
# We allow parent pipelines to pass variables to child pipelines since
# these variables are coming from internal configurations. We will check
# permissions to :set_pipeline_variables when those are injected upstream,
# to the parent pipeline.
# In other scenarios (e.g. multi-project pipelines or run pipeline via UI)
# the variables are provided from the outside and those should be guarded.
return variables if @command.creates_child_pipeline?
if variables.present? && !can?(@command.current_user, :set_pipeline_variables, @command.project)
error("Insufficient permissions to set pipeline variables")
variables = []
end
variables
2018-03-17 18:26:18 +05:30
end
end
end
end
end
end