summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/ci/gitlab_ci_yaml_processor.rb7
-rw-r--r--lib/gitlab/ci/config/node/job.rb1
-rw-r--r--lib/gitlab/ci/config/node/stage.rb16
-rw-r--r--spec/lib/ci/gitlab_ci_yaml_processor_spec.rb4
-rw-r--r--spec/lib/gitlab/ci/config/node/stage_spec.rb71
5 files changed, 15 insertions, 84 deletions
diff --git a/lib/ci/gitlab_ci_yaml_processor.rb b/lib/ci/gitlab_ci_yaml_processor.rb
index 144f9cd7b74..0217a905eac 100644
--- a/lib/ci/gitlab_ci_yaml_processor.rb
+++ b/lib/ci/gitlab_ci_yaml_processor.rb
@@ -105,6 +105,7 @@ module Ci
validate_job_keys!(name, job)
validate_job_types!(name, job)
+ validate_job_stage!(name, job) if job[:stage]
validate_job_variables!(name, job) if job[:variables]
validate_job_cache!(name, job) if job[:cache]
validate_job_artifacts!(name, job) if job[:artifacts]
@@ -153,6 +154,12 @@ module Ci
end
end
+ def validate_job_stage!(name, job)
+ unless job[:stage].is_a?(String) && job[:stage].in?(@stages)
+ raise ValidationError, "#{name} job: stage parameter should be #{@stages.join(", ")}"
+ end
+ end
+
def validate_job_variables!(name, job)
unless validate_variables(job[:variables])
raise ValidationError,
diff --git a/lib/gitlab/ci/config/node/job.rb b/lib/gitlab/ci/config/node/job.rb
index f01a46a8ddc..cca9791fc8e 100644
--- a/lib/gitlab/ci/config/node/job.rb
+++ b/lib/gitlab/ci/config/node/job.rb
@@ -12,7 +12,6 @@ module Gitlab
validates :config, presence: true
with_options on: :processed do
- validates :global, required: true
validates :name, presence: true
validates :name, type: Symbol
end
diff --git a/lib/gitlab/ci/config/node/stage.rb b/lib/gitlab/ci/config/node/stage.rb
index 909358ea170..cbc97641f5a 100644
--- a/lib/gitlab/ci/config/node/stage.rb
+++ b/lib/gitlab/ci/config/node/stage.rb
@@ -10,22 +10,6 @@ module Gitlab
validations do
validates :config, type: String
-
- with_options on: :processed do
- validates :global, required: true
-
- validate do
- unless known?
- errors.add(:config,
- 'should be one of defined stages ' \
- "(#{global.stages.join(', ')})")
- end
- end
- end
- end
-
- def known?
- @global.stages.include?(@config)
end
def self.default
diff --git a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
index e88f5cfc6dd..daa02faf6fb 100644
--- a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
+++ b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
@@ -1089,14 +1089,14 @@ EOT
config = YAML.dump({ rspec: { script: "test", type: "acceptance" } })
expect do
GitlabCiYamlProcessor.new(config, path)
- end.to raise_error(GitlabCiYamlProcessor::ValidationError, "jobs:rspec:type config should be one of defined stages (build, test, deploy)")
+ end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: stage parameter should be build, test, deploy")
end
it "returns errors if job stage is not a defined stage" do
config = YAML.dump({ types: ["build", "test"], rspec: { script: "test", type: "acceptance" } })
expect do
GitlabCiYamlProcessor.new(config, path)
- end.to raise_error(GitlabCiYamlProcessor::ValidationError, "jobs:rspec:type config should be one of defined stages (build, test)")
+ end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: stage parameter should be build, test")
end
it "returns errors if stages is not an array" do
diff --git a/spec/lib/gitlab/ci/config/node/stage_spec.rb b/spec/lib/gitlab/ci/config/node/stage_spec.rb
index 004012f8b38..fb9ec70762a 100644
--- a/spec/lib/gitlab/ci/config/node/stage_spec.rb
+++ b/spec/lib/gitlab/ci/config/node/stage_spec.rb
@@ -1,17 +1,12 @@
require 'spec_helper'
describe Gitlab::Ci::Config::Node::Stage do
- let(:stage) { described_class.new(config, global: global) }
- let(:global) { spy('Global') }
+ let(:stage) { described_class.new(config) }
describe 'validations' do
context 'when stage config value is correct' do
let(:config) { 'build' }
- before do
- allow(global).to receive(:stages).and_return(%w[build])
- end
-
describe '#value' do
it 'returns a stage key' do
expect(stage.value).to eq config
@@ -25,66 +20,12 @@ describe Gitlab::Ci::Config::Node::Stage do
end
end
- context 'when stage config is incorrect' do
- describe '#errors' do
- context 'when reference to global node is not set' do
- let(:stage) { described_class.new('test') }
-
- it 'raises error' do
- expect { stage.validate! }.to raise_error(
- Gitlab::Ci::Config::Node::Entry::InvalidError,
- /Entry needs global attribute set internally./
- )
- end
- end
-
- context 'when value has a wrong type' do
- let(:config) { { test: true } }
-
- it 'reports errors about wrong type' do
- expect(stage.errors)
- .to include 'stage config should be a string'
- end
- end
-
- context 'when stage is not present in global configuration' do
- let(:config) { 'unknown' }
-
- before do
- allow(global)
- .to receive(:stages).and_return(%w[test deploy])
- end
-
- it 'reports error about missing stage' do
- stage.validate!
-
- expect(stage.errors)
- .to include 'stage config should be one of ' \
- 'defined stages (test, deploy)'
- end
- end
- end
- end
- end
-
- describe '#known?' do
- before do
- allow(global).to receive(:stages).and_return(%w[test deploy])
- end
-
- context 'when stage is not known' do
- let(:config) { :unknown }
-
- it 'returns false' do
- expect(stage.known?).to be false
- end
- end
-
- context 'when stage is known' do
- let(:config) { 'test' }
+ context 'when value has a wrong type' do
+ let(:config) { { test: true } }
- it 'returns false' do
- expect(stage.known?).to be true
+ it 'reports errors about wrong type' do
+ expect(stage.errors)
+ .to include 'stage config should be a string'
end
end
end