Commit 97dd007b authored by Max Woolf's avatar Max Woolf

Add support for CI_COMMIT_REF_NAME variable in includes

parent e625c16d
...@@ -426,6 +426,8 @@ In `include` sections in your `.gitlab-ci.yml` file, you can use: ...@@ -426,6 +426,8 @@ In `include` sections in your `.gitlab-ci.yml` file, you can use:
- Project [predefined variables](../variables/predefined_variables.md). - Project [predefined variables](../variables/predefined_variables.md).
- [Custom instance, group, and project variables](../variables/index.md#custom-cicd-variables) - [Custom instance, group, and project variables](../variables/index.md#custom-cicd-variables)
in GitLab 14.2 and later. in GitLab 14.2 and later.
- `$CI_COMMIT_REF_NAME` [predefined variable](../variables/predefined_variables.md) in GitLab 14.2
and later.
```yaml ```yaml
include: include:
......
...@@ -121,17 +121,26 @@ module Gitlab ...@@ -121,17 +121,26 @@ module Gitlab
Gitlab::Ci::Variables::Collection.new.tap do |variables| Gitlab::Ci::Variables::Collection.new.tap do |variables|
break variables unless project break variables unless project
# The order of the next 4 lines is important as priority of CI variables is # The order of the following lines is important as priority of CI variables is
# defined globally within GitLab. # defined globally within GitLab.
# #
# See more detail in the docs: https://docs.gitlab.com/ee/ci/variables/#cicd-variable-precedence # See more detail in the docs: https://docs.gitlab.com/ee/ci/variables/#cicd-variable-precedence
variables.concat(project.predefined_variables) variables.concat(project.predefined_variables)
variables.concat(pipeline_predefined_variables(ref: ref))
variables.concat(project.ci_instance_variables_for(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.group.ci_variables_for(ref, project)) if project.group
variables.concat(project.ci_variables_for(ref: ref)) variables.concat(project.ci_variables_for(ref: ref))
end end
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) def track_and_raise_for_dev_exception(error)
Gitlab::ErrorTracking.track_and_raise_for_dev_exception(error, @context.sentry_payload) Gitlab::ErrorTracking.track_and_raise_for_dev_exception(error, @context.sentry_payload)
end end
......
...@@ -60,7 +60,7 @@ RSpec.describe Gitlab::UsageDataCounters::CiTemplateUniqueCounter do ...@@ -60,7 +60,7 @@ RSpec.describe Gitlab::UsageDataCounters::CiTemplateUniqueCounter do
Gitlab::Ci::Pipeline::Chain::Config::Content::AutoDevops.new(pipeline, command).content, Gitlab::Ci::Pipeline::Chain::Config::Content::AutoDevops.new(pipeline, command).content,
project: project, project: project,
user: double, user: double,
sha: double sha: 'd310cc759caaa20cd05a9e0983d6017896d9c34c'
).execute ).execute
config_source = :auto_devops_source config_source = :auto_devops_source
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment