summaryrefslogtreecommitdiff
path: root/lib/gitlab_ci_yaml_processor.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab_ci_yaml_processor.rb')
-rw-r--r--lib/gitlab_ci_yaml_processor.rb37
1 files changed, 18 insertions, 19 deletions
diff --git a/lib/gitlab_ci_yaml_processor.rb b/lib/gitlab_ci_yaml_processor.rb
index 52f3291..b88b682 100644
--- a/lib/gitlab_ci_yaml_processor.rb
+++ b/lib/gitlab_ci_yaml_processor.rb
@@ -1,9 +1,9 @@
class GitlabCiYamlProcessor
class ValidationError < StandardError;end
- DEFAULT_TYPES = %w(build test deploy)
- DEFAULT_TYPE = 'test'
- ALLOWED_JOB_KEYS = [:tags, :script, :only, :except, :type, :image, :services, :allow_failure, :type]
+ DEFAULT_STAGES = %w(build test deploy)
+ DEFAULT_STAGE = 'test'
+ ALLOWED_JOB_KEYS = [:tags, :script, :only, :except, :type, :image, :services, :allow_failure, :type, :stage]
attr_reader :before_script, :image, :services
@@ -21,8 +21,8 @@ class GitlabCiYamlProcessor
validate!
end
- def builds_for_type_and_ref(type, ref, tag = false)
- builds.select{|build| build[:type] == type && process?(build[:only], build[:except], ref, tag)}
+ def builds_for_stage_and_ref(stage, ref, tag = false)
+ builds.select{|build| build[:stage] == stage && process?(build[:only], build[:except], ref, tag)}
end
def builds
@@ -31,8 +31,8 @@ class GitlabCiYamlProcessor
end
end
- def types
- @types || DEFAULT_TYPES
+ def stages
+ @stages || DEFAULT_STAGES
end
private
@@ -41,8 +41,8 @@ class GitlabCiYamlProcessor
@before_script = @config[:before_script] || []
@image = @config[:image]
@services = @config[:services]
- @types = @config[:types]
- @config.except!(:before_script, :image, :services, :types)
+ @stages = @config[:stages] || @config[:types]
+ @config.except!(:before_script, :image, :services, :types, :stages)
@config.each do |name, param|
raise ValidationError, "Unknown parameter: #{name}" unless param.is_a?(Hash)
@@ -54,7 +54,8 @@ class GitlabCiYamlProcessor
@jobs = {}
@config.each do |key, job|
- @jobs[key] = { type: DEFAULT_TYPE }.merge(job)
+ stage = job[:stage] || job[:type] || DEFAULT_STAGE
+ @jobs[key] = { stage: stage }.merge(job)
end
end
@@ -80,7 +81,7 @@ class GitlabCiYamlProcessor
def build_job(name, job)
{
- type: job[:type],
+ stage: job[:stage],
script: "#{@before_script.join("\n")}\n#{normalize_script(job[:script])}",
tags: job[:tags] || [],
name: name,
@@ -123,8 +124,8 @@ class GitlabCiYamlProcessor
raise ValidationError, "services should be an array of strings"
end
- unless @types.nil? || validate_array_of_strings(@types)
- raise ValidationError, "types should be an array of strings"
+ unless @stages.nil? || validate_array_of_strings(@stages)
+ raise ValidationError, "stages should be an array of strings"
end
@jobs.each do |name, job|
@@ -141,12 +142,10 @@ class GitlabCiYamlProcessor
end
end
- unless job[:type].is_a?(String)
- raise ValidationError, "#{name}: type should be a string"
- end
-
- unless job[:type].in?(types)
- raise ValidationError, "#{name}: type parameter should be #{types.join(", ")}"
+ if job[:stage]
+ unless job[:stage].is_a?(String) && job[:stage].in?(stages)
+ raise ValidationError, "#{name}: stage parameter should be #{stages.join(", ")}"
+ end
end
if job[:image] && !job[:image].is_a?(String)