summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-05-18 14:05:29 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-05-18 14:05:29 +0200
commitd9a3f020be570f135c0ce7c7676b4c1ed332ce1d (patch)
treeb9c28899bdef3238a1def24fda7a3141565882f3
parent9f7deb85b5d6937e6cf7068b864f49693b4a2623 (diff)
downloadgitlab-ce-d9a3f020be570f135c0ce7c7676b4c1ed332ce1d.tar.gz
Separate persisted and runtime pipeline variables
-rw-r--r--app/models/ci/build.rb1
-rw-r--r--app/models/ci/pipeline.rb2
-rw-r--r--spec/models/ci/build_spec.rb8
-rw-r--r--spec/services/ci/create_pipeline_service_spec.rb21
4 files changed, 30 insertions, 2 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index 61c10c427dd..78f054a6527 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -599,6 +599,7 @@ module Ci
break variables unless persisted?
variables
+ .concat(pipeline.persisted_variables)
.append(key: 'CI_JOB_ID', value: id.to_s)
.append(key: 'CI_JOB_TOKEN', value: token, public: false)
.append(key: 'CI_BUILD_ID', value: id.to_s)
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb
index 7d7349b04bc..53af87a271a 100644
--- a/app/models/ci/pipeline.rb
+++ b/app/models/ci/pipeline.rb
@@ -530,7 +530,7 @@ module Ci
end
def predefined_variables
- persisted_variables
+ Gitlab::Ci::Variables::Collection.new
.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/build_spec.rb b/spec/models/ci/build_spec.rb
index dc810489011..d7659a9cb58 100644
--- a/spec/models/ci/build_spec.rb
+++ b/spec/models/ci/build_spec.rb
@@ -629,6 +629,14 @@ describe Ci::Build do
it { is_expected.to eq('review/host') }
end
+
+ context 'when using persisted variables' do
+ let(:build) do
+ create(:ci_build, environment: 'review/x$CI_BUILD_ID')
+ end
+
+ it { is_expected.to eq('review/x') }
+ end
end
describe '#starts_environment?' do
diff --git a/spec/services/ci/create_pipeline_service_spec.rb b/spec/services/ci/create_pipeline_service_spec.rb
index 9a0b6efd8a9..be0255a2ccc 100644
--- a/spec/services/ci/create_pipeline_service_spec.rb
+++ b/spec/services/ci/create_pipeline_service_spec.rb
@@ -395,7 +395,26 @@ describe Ci::CreatePipelineService do
result = execute_service
expect(result).to be_persisted
- expect(Environment.find_by(name: "review/master")).not_to be_nil
+ expect(Environment.find_by(name: "review/master")).to be_present
+ end
+ end
+
+ context 'with environment name including persisted variables' do
+ before do
+ config = YAML.dump(
+ deploy: {
+ environment: { name: "review/id1$CI_PIPELINE_ID/id2$CI_BUILD_ID" },
+ script: 'ls' }
+ )
+
+ stub_ci_pipeline_yaml_file(config)
+ end
+
+ it 'skipps persisted variables in environment name' do
+ result = execute_service
+
+ expect(result).to be_persisted
+ expect(Environment.find_by(name: "review/id1/id2")).to be_present
end
end