Commit dff10976 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Move job dependencies entry to the new CI config

parent f83bccfe
...@@ -98,21 +98,22 @@ module Ci ...@@ -98,21 +98,22 @@ module Ci
@jobs = @ci_config.jobs @jobs = @ci_config.jobs
@jobs.each do |name, job| @jobs.each do |name, job|
validate_job!(name, job) # logical validation for job
validate_job_stage!(name, job)
validate_job_dependencies!(name, job)
end end
end end
def yaml_variables(name) def yaml_variables(name)
variables = global_variables.merge(job_variables(name)) variables = (@variables || {})
.merge(job_variables(name))
variables.map do |key, value| variables.map do |key, value|
{ key: key, value: value, public: true } { key: key, value: value, public: true }
end end
end end
def global_variables
@variables || {}
end
def job_variables(name) def job_variables(name)
job = @jobs[name.to_sym] job = @jobs[name.to_sym]
return {} unless job return {} unless job
...@@ -120,21 +121,16 @@ module Ci ...@@ -120,21 +121,16 @@ module Ci
job[:variables] || {} job[:variables] || {}
end end
def validate_job!(name, job)
validate_job_stage!(name, job) if job[:stage]
validate_job_dependencies!(name, job) if job[:dependencies]
end
def validate_job_stage!(name, job) def validate_job_stage!(name, job)
return unless job[:stage]
unless job[:stage].is_a?(String) && job[:stage].in?(@stages) unless job[:stage].is_a?(String) && job[:stage].in?(@stages)
raise ValidationError, "#{name} job: stage parameter should be #{@stages.join(", ")}" raise ValidationError, "#{name} job: stage parameter should be #{@stages.join(", ")}"
end end
end end
def validate_job_dependencies!(name, job) def validate_job_dependencies!(name, job)
unless validate_array_of_strings(job[:dependencies]) return unless job[:dependencies]
raise ValidationError, "#{name} job: dependencies parameter should be an array of strings"
end
stage_index = @stages.index(job[:stage]) stage_index = @stages.index(job[:stage])
......
...@@ -13,7 +13,7 @@ module Gitlab ...@@ -13,7 +13,7 @@ module Gitlab
type stage when artifacts cache dependencies before_script type stage when artifacts cache dependencies before_script
after_script variables environment] after_script variables environment]
attributes :tags, :allow_failure, :when, :environment attributes :tags, :allow_failure, :when, :environment, :dependencies
validations do validations do
validates :config, allowed_keys: ALLOWED_KEYS validates :config, allowed_keys: ALLOWED_KEYS
...@@ -37,6 +37,8 @@ module Gitlab ...@@ -37,6 +37,8 @@ module Gitlab
format: { format: {
with: Gitlab::Regex.environment_name_regex, with: Gitlab::Regex.environment_name_regex,
message: Gitlab::Regex.environment_name_regex_message } message: Gitlab::Regex.environment_name_regex_message }
validates :dependencies, array_of_strings: true
end end
end end
......
...@@ -1239,7 +1239,7 @@ EOT ...@@ -1239,7 +1239,7 @@ EOT
config = YAML.dump({ types: ["build", "test"], rspec: { script: "test", dependencies: "string" } }) config = YAML.dump({ types: ["build", "test"], rspec: { script: "test", dependencies: "string" } })
expect do expect do
GitlabCiYamlProcessor.new(config) GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: dependencies parameter should be an array of strings") end.to raise_error(GitlabCiYamlProcessor::ValidationError, "jobs:rspec dependencies should be an array of strings")
end end
end end
......
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