debian-mirror-gitlab/lib/gitlab/ci/build/context/build.rb

57 lines
1.4 KiB
Ruby
Raw Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
module Gitlab
module Ci
module Build
module Context
class Build < Base
include Gitlab::Utils::StrongMemoize
attr_reader :attributes
2023-03-04 22:38:38 +05:30
def initialize(pipeline, attributes = {}, build = nil)
2019-12-26 22:10:19 +05:30
super(pipeline)
2023-03-04 22:38:38 +05:30
@build = build
2019-12-26 22:10:19 +05:30
@attributes = attributes
end
def variables
2023-03-04 22:38:38 +05:30
build.scoped_variables
2019-12-26 22:10:19 +05:30
end
2023-03-04 22:38:38 +05:30
strong_memoize_attr :variables
2019-12-26 22:10:19 +05:30
private
2023-03-04 22:38:38 +05:30
def build
@build || stub_build
end
2019-12-26 22:10:19 +05:30
def stub_build
2023-03-04 22:38:38 +05:30
# This is a temporary piece of technical debt to allow us access
# to the CI variables to evaluate rules before we persist a Build
# with the result. We should refactor away the extra Build.new,
# but be able to get CI Variables directly from the Seed::Build.
2019-12-26 22:10:19 +05:30
::Ci::Build.new(build_attributes)
end
def build_attributes
2022-10-11 01:57:18 +05:30
attributes.merge(pipeline_attributes, ci_stage_attributes)
end
def ci_stage_attributes
{
ci_stage: ::Ci::Stage.new(
name: attributes[:stage],
position: attributes[:stage_idx],
pipeline: pipeline_attributes[:pipeline],
project: pipeline_attributes[:project]
)
}
2019-12-26 22:10:19 +05:30
end
end
end
end
end
end