diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2016-04-19 11:12:40 +0000 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2016-04-19 11:12:40 +0000 |
commit | c7bd7b6dd83a73919b350d0f89e07830b2cd1332 (patch) | |
tree | eff6ef4d1508022940b32a9dbc8ea2ccb686579a /lib | |
parent | 479f4cccf15c8ff12ccaefa6ba2e46e0aefbe2ab (diff) | |
parent | 3f66f4470a7399a5079de04b8b2506edc159b90a (diff) | |
download | gitlab-ce-c7bd7b6dd83a73919b350d0f89e07830b2cd1332.tar.gz |
Merge branch 'make-before-after-overridable' into 'master'
Make before_script and after_script overridable
This is makes it possible to overwrite the before_script and after_script at job level.
This is continuation of https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/3771
See merge request !3772
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ci/gitlab_ci_yaml_processor.rb | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/lib/ci/gitlab_ci_yaml_processor.rb b/lib/ci/gitlab_ci_yaml_processor.rb index d8a7fcfe15e..ff9887cba1e 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, :after_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, :variables] + :dependencies, :before_script, :after_script, :variables] attr_reader :before_script, :after_script, :image, :services, :path, :cache @@ -84,7 +84,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], @@ -97,19 +97,11 @@ module Ci artifacts: job[:artifacts], cache: job[:cache] || @cache, dependencies: job[:dependencies], - after_script: @after_script, + after_script: job[:after_script] || @after_script, }.compact } end - def normalize_script(script) - if script.is_a? Array - script.join("\n") - else - script - end - end - def validate! validate_global! @@ -168,6 +160,7 @@ module Ci validate_job_name!(name) validate_job_keys!(name, job) validate_job_types!(name, job) + validate_job_script!(name, job) validate_job_stage!(name, job) if job[:stage] validate_job_variables!(name, job) if job[:variables] @@ -191,10 +184,6 @@ module Ci end def validate_job_types!(name, job) - if !validate_string(job[:script]) && !validate_array_of_strings(job[:script]) - raise ValidationError, "#{name} job: script should be a string or an array of a strings" - end - if job[:image] && !validate_string(job[:image]) raise ValidationError, "#{name} job: image should be a string" end @@ -224,6 +213,20 @@ module Ci end end + def validate_job_script!(name, job) + if !validate_string(job[:script]) && !validate_array_of_strings(job[:script]) + 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[:after_script] && !validate_array_of_strings(job[:after_script]) + raise ValidationError, "#{name} job: after_script should be an array of strings" + 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(", ")}" |