diff options
| author | Kamil Trzciński <ayufan@ayufan.eu> | 2016-04-19 11:11:31 +0000 |
|---|---|---|
| committer | Kamil Trzciński <ayufan@ayufan.eu> | 2016-04-19 11:11:31 +0000 |
| commit | 479f4cccf15c8ff12ccaefa6ba2e46e0aefbe2ab (patch) | |
| tree | 6ebf33a7a6c21db7ec1a645d160b1e1a73541f91 /lib | |
| parent | 51b777fa9c0530cd2735f207e0d96d210c08fdca (diff) | |
| parent | 0ce5cc99621c84dfc61f6105d177ced4d9a4ed85 (diff) | |
| download | gitlab-ce-479f4cccf15c8ff12ccaefa6ba2e46e0aefbe2ab.tar.gz | |
Merge branch 'after-script' into 'master'
Implement after_script which allows to do cleanups as part of the build process
This implements `after_script` in global context.
The `after_script` will be executed always after the job, even if the job were canceled.
This requires changes on Runner side that will be implemented in 1.2.
cc @tmaczukin @grzesiek
See merge request !3771
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/ci/gitlab_ci_yaml_processor.rb | 48 |
1 files changed, 30 insertions, 18 deletions
diff --git a/lib/ci/gitlab_ci_yaml_processor.rb b/lib/ci/gitlab_ci_yaml_processor.rb index b8ede3a7edc..d8a7fcfe15e 100644 --- a/lib/ci/gitlab_ci_yaml_processor.rb +++ b/lib/ci/gitlab_ci_yaml_processor.rb @@ -4,12 +4,12 @@ module Ci DEFAULT_STAGES = %w(build test deploy) DEFAULT_STAGE = 'test' - ALLOWED_YAML_KEYS = [:before_script, :image, :services, :types, :stages, :variables, :cache] + 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] - attr_reader :before_script, :image, :services, :path, :cache + attr_reader :before_script, :after_script, :image, :services, :path, :cache def initialize(config, path = nil) @config = YAML.safe_load(config, [Symbol], [], true) @@ -55,6 +55,7 @@ module Ci def initial_parsing @before_script = @config[:before_script] || [] + @after_script = @config[:after_script] @image = @config[:image] @services = @config[:services] @stages = @config[:stages] || @config[:types] @@ -96,6 +97,7 @@ module Ci artifacts: job[:artifacts], cache: job[:cache] || @cache, dependencies: job[:dependencies], + after_script: @after_script, }.compact } end @@ -109,10 +111,26 @@ module Ci end def validate! + validate_global! + + @jobs.each do |name, job| + validate_job!(name, job) + end + + true + end + + private + + def validate_global! unless validate_array_of_strings(@before_script) raise ValidationError, "before_script should be an array of strings" end + unless @after_script.nil? || validate_array_of_strings(@after_script) + raise ValidationError, "after_script should be an array of strings" + end + unless @image.nil? || @image.is_a?(String) raise ValidationError, "image should be a string" end @@ -129,25 +147,21 @@ module Ci raise ValidationError, "variables should be a map of key-value strings" end - if @cache - if @cache[:key] && !validate_string(@cache[:key]) - raise ValidationError, "cache:key parameter should be a string" - end - - if @cache[:untracked] && !validate_boolean(@cache[:untracked]) - raise ValidationError, "cache:untracked parameter should be an boolean" - end + validate_global_cache! if @cache + end - if @cache[:paths] && !validate_array_of_strings(@cache[:paths]) - raise ValidationError, "cache:paths parameter should be an array of strings" - end + def validate_global_cache! + if @cache[:key] && !validate_string(@cache[:key]) + raise ValidationError, "cache:key parameter should be a string" end - @jobs.each do |name, job| - validate_job!(name, job) + if @cache[:untracked] && !validate_boolean(@cache[:untracked]) + raise ValidationError, "cache:untracked parameter should be an boolean" end - true + if @cache[:paths] && !validate_array_of_strings(@cache[:paths]) + raise ValidationError, "cache:paths parameter should be an array of strings" + end end def validate_job!(name, job) @@ -162,8 +176,6 @@ module Ci validate_job_dependencies!(name, job) if job[:dependencies] end - private - def validate_job_name!(name) if name.blank? || !validate_string(name) raise ValidationError, "job name should be non-empty string" |
