Commit f091fe3d authored by Sean Carroll's avatar Sean Carroll Committed by Robert Speicher

Move $CI_DEPLOY_FREEZE variable calculation to pipeline

Closes https://gitlab.com/gitlab-org/gitlab/issues/220944

See merge request https://gitlab.com/gitlab-org/gitlab/merge_requests/35226
parent 6448f2b7
......@@ -539,7 +539,6 @@ module Ci
.concat(job_variables)
.concat(environment_changed_page_variables)
.concat(persisted_environment_variables)
.concat(deploy_freeze_variables)
.to_runner_variables
end
end
......@@ -595,18 +594,6 @@ module Ci
end
end
def deploy_freeze_variables
Gitlab::Ci::Variables::Collection.new.tap do |variables|
break variables unless freeze_period?
variables.append(key: 'CI_DEPLOY_FREEZE', value: 'true')
end
end
def freeze_period?
Ci::FreezePeriodStatus.new(project: project).execute
end
def dependency_variables
return [] if all_dependencies.empty?
......
......@@ -604,6 +604,10 @@ module Ci
project.deployment_platform&.active?
end
def freeze_period?
Ci::FreezePeriodStatus.new(project: project).execute
end
def has_warnings?
number_of_warnings.positive?
end
......@@ -714,6 +718,7 @@ module Ci
end
variables.append(key: 'CI_KUBERNETES_ACTIVE', value: 'true') if has_kubernetes_active?
variables.append(key: 'CI_DEPLOY_FREEZE', value: 'true') if freeze_period?
if external_pull_request_event? && external_pull_request
variables.concat(external_pull_request.predefined_variables)
......
---
title: Properly set CI_DEPLOY_FREEZE variable in pipelines
merge_request: 35226
author:
type: fixed
......@@ -2974,19 +2974,6 @@ RSpec.describe Ci::Build do
it { is_expected.to include(deployment_variable) }
end
context 'when build has a freeze period' do
let(:freeze_variable) { { key: 'CI_DEPLOY_FREEZE', value: 'true', masked: false, public: true } }
before do
expect_next_instance_of(Ci::FreezePeriodStatus) do |freeze_period|
expect(freeze_period).to receive(:execute)
.and_return(true)
end
end
it { is_expected.to include(freeze_variable) }
end
context 'when project has default CI config path' do
let(:ci_config_path) { { key: 'CI_CONFIG_PATH', value: '.gitlab-ci.yml', public: true, masked: false } }
......
......@@ -2205,6 +2205,83 @@ RSpec.describe Ci::CreatePipelineService do
expect(find_job('job-7').when).to eq('on_failure')
end
end
context 'with deploy freeze period `if:` clause' do
# '0 23 * * 5' == "At 23:00 on Friday."", '0 7 * * 1' == "At 07:00 on Monday.""
let!(:freeze_period) { create(:ci_freeze_period, project: project, freeze_start: '0 23 * * 5', freeze_end: '0 7 * * 1') }
context 'with 2 jobs' do
let(:config) do
<<-EOY
stages:
- test
- deploy
test-job:
script:
- echo 'running TEST stage'
deploy-job:
stage: deploy
script:
- echo 'running DEPLOY stage'
rules:
- if: $CI_DEPLOY_FREEZE == null
EOY
end
context 'when outside freeze period' do
Timecop.freeze(2020, 4, 10, 22, 59) do
it 'creates two jobs' do
expect(pipeline).to be_persisted
expect(build_names).to contain_exactly('test-job', 'deploy-job')
end
end
end
context 'when inside freeze period' do
it 'creates one job' do
Timecop.freeze(2020, 4, 10, 23, 1) do
expect(pipeline).to be_persisted
expect(build_names).to contain_exactly('test-job')
end
end
end
end
context 'with 1 job' do
let(:config) do
<<-EOY
stages:
- deploy
deploy-job:
stage: deploy
script:
- echo 'running DEPLOY stage'
rules:
- if: $CI_DEPLOY_FREEZE == null
EOY
end
context 'when outside freeze period' do
Timecop.freeze(2020, 4, 10, 22, 59) do
it 'creates two jobs' do
expect(pipeline).to be_persisted
expect(build_names).to contain_exactly('deploy-job')
end
end
end
context 'when inside freeze period' do
it 'does not create the pipeline' do
Timecop.freeze(2020, 4, 10, 23, 1) do
expect(pipeline).not_to be_persisted
end
end
end
end
end
end
end
......
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