summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-05-18 11:28:32 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-05-18 11:28:32 +0200
commit9f7deb85b5d6937e6cf7068b864f49693b4a2623 (patch)
tree7d6805454a87d5f187086180c3bcd03e61556610
parent769c4a6197dfd72aca06abd20fa1ffe5c568ed24 (diff)
downloadgitlab-ce-9f7deb85b5d6937e6cf7068b864f49693b4a2623.tar.gz
Do not allow to use `CI_PIPELINE_ID` in environment name
-rw-r--r--app/models/ci/pipeline.rb9
-rw-r--r--spec/models/ci/pipeline_spec.rb22
2 files changed, 29 insertions, 2 deletions
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb
index c26f0b6dcdc..7d7349b04bc 100644
--- a/app/models/ci/pipeline.rb
+++ b/app/models/ci/pipeline.rb
@@ -523,9 +523,14 @@ module Ci
strong_memoize(:legacy_trigger) { trigger_requests.first }
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
- Gitlab::Ci::Variables::Collection.new
- .append(key: 'CI_PIPELINE_ID', value: id.to_s)
+ persisted_variables
.append(key: 'CI_CONFIG_PATH', value: ci_yaml_file_path)
.append(key: 'CI_PIPELINE_SOURCE', value: source.to_s)
.append(key: 'CI_COMMIT_MESSAGE', value: git_commit_message)
diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb
index e7845b693a1..0e393aa362b 100644
--- a/spec/models/ci/pipeline_spec.rb
+++ b/spec/models/ci/pipeline_spec.rb
@@ -167,6 +167,28 @@ describe Ci::Pipeline, :mailer do
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
subject { pipeline.predefined_variables }