diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 09:08:42 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 09:08:42 +0000 |
commit | b76ae638462ab0f673e5915986070518dd3f9ad3 (patch) | |
tree | bdab0533383b52873be0ec0eb4d3c66598ff8b91 /lib/gitlab/ci/config.rb | |
parent | 434373eabe7b4be9593d18a585fb763f1e5f1a6f (diff) | |
download | gitlab-ce-b76ae638462ab0f673e5915986070518dd3f9ad3.tar.gz |
Add latest changes from gitlab-org/gitlab@14-2-stable-eev14.2.0-rc42
Diffstat (limited to 'lib/gitlab/ci/config.rb')
-rw-r--r-- | lib/gitlab/ci/config.rb | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/lib/gitlab/ci/config.rb b/lib/gitlab/ci/config.rb index 9c6428d701c..aceaf012f7e 100644 --- a/lib/gitlab/ci/config.rb +++ b/lib/gitlab/ci/config.rb @@ -17,13 +17,13 @@ module Gitlab Config::Yaml::Tags::TagError ].freeze - attr_reader :root, :context, :ref, :source + attr_reader :root, :context, :source_ref_path, :source - def initialize(config, project: nil, sha: nil, user: nil, parent_pipeline: nil, ref: nil, source: nil) - @context = build_context(project: project, sha: sha, user: user, parent_pipeline: parent_pipeline) + def initialize(config, project: nil, sha: nil, user: nil, parent_pipeline: nil, source_ref_path: nil, source: nil) + @context = build_context(project: project, sha: sha, user: user, parent_pipeline: parent_pipeline, ref: source_ref_path) @context.set_deadline(TIMEOUT_SECONDS) - @ref = ref + @source_ref_path = source_ref_path @source = source @config = expand_config(config) @@ -108,13 +108,37 @@ module Gitlab end end - def build_context(project:, sha:, user:, parent_pipeline:) + def build_context(project:, sha:, user:, parent_pipeline:, ref:) Config::External::Context.new( project: project, sha: sha || find_sha(project), user: user, parent_pipeline: parent_pipeline, - variables: project&.predefined_variables&.to_runner_variables) + variables: build_variables(project: project, ref: ref)) + end + + def build_variables(project:, ref:) + Gitlab::Ci::Variables::Collection.new.tap do |variables| + break variables unless project + + # The order of the following lines is important as priority of CI variables is + # defined globally within GitLab. + # + # See more detail in the docs: https://docs.gitlab.com/ee/ci/variables/#cicd-variable-precedence + variables.concat(project.predefined_variables) + variables.concat(pipeline_predefined_variables(ref: ref)) + variables.concat(project.ci_instance_variables_for(ref: ref)) + variables.concat(project.group.ci_variables_for(ref, project)) if project.group + variables.concat(project.ci_variables_for(ref: ref)) + end + end + + # https://gitlab.com/gitlab-org/gitlab/-/issues/337633 aims to add all predefined variables + # to this list, but only CI_COMMIT_REF_NAME is available right now to support compliance pipelines. + def pipeline_predefined_variables(ref:) + Gitlab::Ci::Variables::Collection.new.tap do |v| + v.append(key: 'CI_COMMIT_REF_NAME', value: ref) + end end def track_and_raise_for_dev_exception(error) |