Commit b190dd86 authored by Dylan Griffith's avatar Dylan Griffith

Merge branch 'requirements_ci_var' into 'master'

Include CI_HAS_OPEN_REQUIREMENTS variable

See merge request gitlab-org/gitlab!34419
parents 921235e8 0d240b27
......@@ -58,6 +58,7 @@ You can add a command to your `.gitlab-ci.yml` file to
| `CI_EXTERNAL_PULL_REQUEST_SOURCE_BRANCH_SHA` | 12.3 | all | The HEAD SHA of the source branch of the pull request if [the pipelines are for external pull requests](../ci_cd_for_external_repos/index.md#pipelines-for-external-pull-requests). Available only if `only: [external_pull_requests]` or [`rules`](../yaml/README.md#rules) syntax is used and the pull request is open. |
| `CI_EXTERNAL_PULL_REQUEST_TARGET_BRANCH_NAME` | 12.3 | all | The target branch name of the pull request if [the pipelines are for external pull requests](../ci_cd_for_external_repos/index.md#pipelines-for-external-pull-requests). Available only if `only: [external_pull_requests]` or [`rules`](../yaml/README.md#rules) syntax is used and the pull request is open. |
| `CI_EXTERNAL_PULL_REQUEST_TARGET_BRANCH_SHA` | 12.3 | all | The HEAD SHA of the target branch of the pull request if [the pipelines are for external pull requests](../ci_cd_for_external_repos/index.md#pipelines-for-external-pull-requests). Available only if `only: [external_pull_requests]` or [`rules`](../yaml/README.md#rules) syntax is used and the pull request is open. |
| `CI_HAS_OPEN_REQUIREMENTS` | 13.1 | all | Included with the value `true` only if the pipeline's project has any open [requirements](../../user/project/requirements/index.md). Not included if there are no open requirements for the pipeline's project. |
| `CI_JOB_ID` | 9.0 | all | The unique ID of the current job that GitLab CI/CD uses internally |
| `CI_JOB_IMAGE` | 12.9 | 12.9 | The name of the image running the CI job |
| `CI_JOB_MANUAL` | 8.12 | all | The flag to indicate that job was manually started |
......
......@@ -714,6 +714,11 @@ module EE
feature_available?(:jira_dev_panel_integration) && JiraConnectSubscription.for_project(self).exists?
end
override :predefined_variables
def predefined_variables
super.concat(requirements_ci_variables)
end
private
def group_hooks
......@@ -767,6 +772,14 @@ module EE
approval_rules.regular_or_any_approver.order(rule_type: :desc, id: :asc)
end
end
def requirements_ci_variables
::Gitlab::Ci::Variables::Collection.new.tap do |variables|
if requirements.opened.any?
variables.append(key: 'CI_HAS_OPEN_REQUIREMENTS', value: 'true')
end
end
end
end
end
......
---
title: Added CI_HAS_OPEN_REQUIREMENTS environment variable.
merge_request: 34419
author:
type: changed
......@@ -137,6 +137,23 @@ RSpec.describe Ci::Build do
end
end
end
describe 'variable CI_HAS_OPEN_REQUIREMENTS' do
it "is included with value 'true' if there are open requirements" do
create(:requirement, project: project)
expect(subject).to include({ key: 'CI_HAS_OPEN_REQUIREMENTS',
value: 'true', public: true, masked: false })
end
it 'is not included if there are no open requirements' do
create(:requirement, project: project, state: :archived)
requirement_variable = subject.find { |var| var[:key] == 'CI_HAS_OPEN_REQUIREMENTS' }
expect(requirement_variable).to be_nil
end
end
end
describe '#collect_security_reports!' do
......
......@@ -2407,13 +2407,13 @@ describe Ci::Build do
allow(build).to receive(:job_jwt_variables) { [job_jwt_var] }
allow(build).to receive(:dependency_variables) { [job_dependency_var] }
allow_any_instance_of(Project)
allow(build.project)
.to receive(:predefined_variables) { [project_pre_var] }
project.variables.create!(key: 'secret', value: 'value')
allow_any_instance_of(Ci::Pipeline)
.to receive(:predefined_variables) { [pipeline_pre_var] }
allow(build.pipeline)
.to receive(:predefined_variables).and_return([pipeline_pre_var])
end
it 'returns variables in order depending on resource hierarchy' do
......
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