Commit 9f7deb85 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Do not allow to use `CI_PIPELINE_ID` in environment name

parent 769c4a61
...@@ -523,9 +523,14 @@ module Ci ...@@ -523,9 +523,14 @@ module Ci
strong_memoize(:legacy_trigger) { trigger_requests.first } strong_memoize(:legacy_trigger) { trigger_requests.first }
end end
def persisted_variables
Gitlab::Ci::Variables::Collection.new.tap do |variables|
variables.append(key: 'CI_PIPELINE_ID', value: id.to_s) if persisted?
end
end
def predefined_variables def predefined_variables
Gitlab::Ci::Variables::Collection.new persisted_variables
.append(key: 'CI_PIPELINE_ID', value: id.to_s)
.append(key: 'CI_CONFIG_PATH', value: ci_yaml_file_path) .append(key: 'CI_CONFIG_PATH', value: ci_yaml_file_path)
.append(key: 'CI_PIPELINE_SOURCE', value: source.to_s) .append(key: 'CI_PIPELINE_SOURCE', value: source.to_s)
.append(key: 'CI_COMMIT_MESSAGE', value: git_commit_message) .append(key: 'CI_COMMIT_MESSAGE', value: git_commit_message)
......
...@@ -167,6 +167,28 @@ describe Ci::Pipeline, :mailer do ...@@ -167,6 +167,28 @@ describe Ci::Pipeline, :mailer do
end end
end end
describe '#persisted_variables' do
context 'when pipeline is not persisted yet' do
subject { build(:ci_pipeline).persisted_variables }
it 'does not contain some variables' do
keys = subject.map { |variable| variable[:key] }
expect(keys).not_to include 'CI_PIPELINE_ID'
end
end
context 'when pipeline is persisted' do
subject { build_stubbed(:ci_pipeline).persisted_variables }
it 'does not contain some variables' do
keys = subject.map { |variable| variable[:key] }
expect(keys).to include 'CI_PIPELINE_ID'
end
end
end
describe '#predefined_variables' do describe '#predefined_variables' do
subject { pipeline.predefined_variables } subject { pipeline.predefined_variables }
......
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