summaryrefslogtreecommitdiff
path: root/lib/ci
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2016-04-16 18:49:15 +0200
committerKamil Trzcinski <ayufan@ayufan.eu>2016-04-16 19:22:49 +0200
commit4cc9a02ee033564b62b45977571319d129df465b (patch)
tree72073bed6119fd3b411c0c08d3b459d6620caf6c /lib/ci
parentb340b59743e8cd47fc1f4fa2020b400d82bfd86e (diff)
downloadgitlab-ce-4cc9a02ee033564b62b45977571319d129df465b.tar.gz
Allow the before_script and finally_script to be overwritten in context of job
Diffstat (limited to 'lib/ci')
-rw-r--r--lib/ci/gitlab_ci_yaml_processor.rb22
1 files changed, 11 insertions, 11 deletions
diff --git a/lib/ci/gitlab_ci_yaml_processor.rb b/lib/ci/gitlab_ci_yaml_processor.rb
index be2462949f1..2e5b84a57d6 100644
--- a/lib/ci/gitlab_ci_yaml_processor.rb
+++ b/lib/ci/gitlab_ci_yaml_processor.rb
@@ -7,7 +7,7 @@ module Ci
ALLOWED_YAML_KEYS = [:before_script, :finally_script, :image, :services, :types, :stages, :variables, :cache]
ALLOWED_JOB_KEYS = [:tags, :script, :only, :except, :type, :image, :services,
:allow_failure, :type, :stage, :when, :artifacts, :cache,
- :dependencies]
+ :dependencies, :before_script, :finally_script]
attr_reader :before_script, :finally_script, :image, :services, :variables, :path, :cache
@@ -73,7 +73,7 @@ module Ci
{
stage_idx: stages.index(job[:stage]),
stage: job[:stage],
- commands: "#{@before_script.join("\n")}\n#{normalize_script(job[:script])}",
+ commands: [job[:before_script] || @before_script, job[:script]].flatten.join("\n"),
tag_list: job[:tags] || [],
name: name,
only: job[:only],
@@ -86,19 +86,11 @@ module Ci
artifacts: job[:artifacts],
cache: job[:cache] || @cache,
dependencies: job[:dependencies],
- finally_script: @finally_script,
+ finally_script: job[:finally_script] || @finally_script,
}.compact
}
end
- def normalize_script(script)
- if script.is_a? Array
- script.join("\n")
- else
- script
- end
- end
-
def validate!
unless validate_array_of_strings(@before_script)
raise ValidationError, "before_script should be an array of strings"
@@ -177,6 +169,14 @@ module Ci
raise ValidationError, "#{name} job: script should be a string or an array of a strings"
end
+ if job[:before_script] && !validate_array_of_strings(job[:before_script])
+ raise ValidationError, "#{name} job: before_script should be an array of strings"
+ end
+
+ if job[:finally_script] && !validate_array_of_strings(job[:finally_script])
+ raise ValidationError, "#{name} job: finally_script should be an array of strings"
+ end
+
if job[:image] && !validate_string(job[:image])
raise ValidationError, "#{name} job: image should be a string"
end