summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-04-18 12:41:13 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-04-18 13:36:52 +0200
commit1339fda1cd3325c0186b5f1b53444e7319ad3cb6 (patch)
tree3a549c546b561ecd3f124d5a115bc9c7ef18543c
parent2972a991df0e7a0071de1803205814f2d105df46 (diff)
downloadgitlab-ce-feature/ci-job-env-variables.tar.gz
Minor refactorings in CI configfeature/ci-job-env-variables
-rw-r--r--lib/ci/gitlab_ci_yaml_processor.rb11
-rw-r--r--spec/lib/ci/gitlab_ci_yaml_processor_spec.rb6
2 files changed, 10 insertions, 7 deletions
diff --git a/lib/ci/gitlab_ci_yaml_processor.rb b/lib/ci/gitlab_ci_yaml_processor.rb
index ddf34b60a85..b8ede3a7edc 100644
--- a/lib/ci/gitlab_ci_yaml_processor.rb
+++ b/lib/ci/gitlab_ci_yaml_processor.rb
@@ -45,7 +45,10 @@ module Ci
end
def job_variables(name)
- @jobs[name.to_sym].try(:fetch, :variables, []) || []
+ job = @jobs[name.to_sym]
+ return [] unless job
+
+ job.fetch(:variables, [])
end
private
@@ -123,7 +126,7 @@ module Ci
end
unless @variables.nil? || validate_variables(@variables)
- raise ValidationError, "variables should be a map of key-valued strings"
+ raise ValidationError, "variables should be a map of key-value strings"
end
if @cache
@@ -216,9 +219,9 @@ module Ci
end
def validate_job_variables!(name, job)
- if job[:variables] && !validate_variables(job[:variables])
+ unless validate_variables(job[:variables])
raise ValidationError,
- "#{name} job: variables should be a map of key-valued strings"
+ "#{name} job: variables should be a map of key-value strings"
end
end
diff --git a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
index 8813a724774..5f4b63bcafb 100644
--- a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
+++ b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
@@ -786,14 +786,14 @@ EOT
config = YAML.dump({ variables: "test", rspec: { script: "test" } })
expect do
GitlabCiYamlProcessor.new(config, path)
- end.to raise_error(GitlabCiYamlProcessor::ValidationError, "variables should be a map of key-valued strings")
+ end.to raise_error(GitlabCiYamlProcessor::ValidationError, "variables should be a map of key-value strings")
end
- it "returns errors if variables is not a map of key-valued strings" do
+ it "returns errors if variables is not a map of key-value strings" do
config = YAML.dump({ variables: { test: false }, rspec: { script: "test" } })
expect do
GitlabCiYamlProcessor.new(config, path)
- end.to raise_error(GitlabCiYamlProcessor::ValidationError, "variables should be a map of key-valued strings")
+ end.to raise_error(GitlabCiYamlProcessor::ValidationError, "variables should be a map of key-value strings")
end
it "returns errors if job when is not on_success, on_failure or always" do