diff options
-rw-r--r-- | lib/ci/gitlab_ci_yaml_processor.rb | 13 | ||||
-rw-r--r-- | lib/gitlab/ci/config.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/ci/config/node/global.rb | 3 | ||||
-rw-r--r-- | lib/gitlab/ci/config/node/script.rb | 7 | ||||
-rw-r--r-- | spec/lib/ci/gitlab_ci_yaml_processor_spec.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/node/factory_spec.rb | 4 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/node/global_spec.rb | 13 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/node/script_spec.rb | 4 |
8 files changed, 24 insertions, 24 deletions
diff --git a/lib/ci/gitlab_ci_yaml_processor.rb b/lib/ci/gitlab_ci_yaml_processor.rb index 2cb46448e76..c0f2a258836 100644 --- a/lib/ci/gitlab_ci_yaml_processor.rb +++ b/lib/ci/gitlab_ci_yaml_processor.rb @@ -14,7 +14,7 @@ module Ci ALLOWED_CACHE_KEYS = [:key, :untracked, :paths] ALLOWED_ARTIFACTS_KEYS = [:name, :untracked, :paths, :when, :expire_in] - attr_reader :after_script, :path, :cache + attr_reader :path, :cache def initialize(config, path = nil) @ci_config = Gitlab::Ci::Config.new(config) @@ -65,10 +65,9 @@ module Ci def initial_parsing @before_script = @ci_config.before_script @image = @ci_config.image - - @after_script = @config[:after_script] - @image = @config[:image] + @after_script = @ci_config.after_script @services = @ci_config.services + @stages = @config[:stages] || @config[:types] @variables = @config[:variables] || {} @cache = @config[:cache] @@ -93,7 +92,7 @@ module Ci { stage_idx: stages.index(job[:stage]), stage: job[:stage], - commands: [job[:before_script] || [@before_script], job[:script]].flatten.compact.join("\n"), + commands: [job[:before_script] || @before_script, job[:script]].flatten.compact.join("\n"), tag_list: job[:tags] || [], name: name, only: job[:only], @@ -123,10 +122,6 @@ module Ci end def validate_global! - unless @after_script.nil? || validate_array_of_strings(@after_script) - raise ValidationError, "after_script should be an array of strings" - end - unless @stages.nil? || validate_array_of_strings(@stages) raise ValidationError, "stages should be an array of strings" end diff --git a/lib/gitlab/ci/config.rb b/lib/gitlab/ci/config.rb index fb93d36c48f..8475e47d2b0 100644 --- a/lib/gitlab/ci/config.rb +++ b/lib/gitlab/ci/config.rb @@ -7,7 +7,7 @@ module Gitlab ## # Temporary delegations that should be removed after refactoring # - delegate :before_script, :image, :services, to: :@global + delegate :before_script, :image, :services, :after_script, to: :@global def initialize(config) @config = Loader.new(config).load! diff --git a/lib/gitlab/ci/config/node/global.rb b/lib/gitlab/ci/config/node/global.rb index 03ed7808d2f..7b8d6d63a08 100644 --- a/lib/gitlab/ci/config/node/global.rb +++ b/lib/gitlab/ci/config/node/global.rb @@ -17,6 +17,9 @@ module Gitlab allow_node :services, Services, description: 'Docker images that will be linked to the container.' + + allow_node :after_script, Script, + description: 'Script that will be executed after each job.' end end end diff --git a/lib/gitlab/ci/config/node/script.rb b/lib/gitlab/ci/config/node/script.rb index c044f5c5e71..7bbd6291c2d 100644 --- a/lib/gitlab/ci/config/node/script.rb +++ b/lib/gitlab/ci/config/node/script.rb @@ -5,11 +5,6 @@ module Gitlab ## # Entry that represents a script. # - # Each element in the value array is a command that will be executed - # by GitLab Runner. Currently we concatenate these commands with - # new line character as a separator, what is compatible with - # implementation in Runner. - # class Script < Entry include Validatable @@ -18,7 +13,7 @@ module Gitlab end def value - @config.join("\n") + @config end end end diff --git a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb index bed174e2495..35309eec597 100644 --- a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb +++ b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb @@ -965,7 +965,7 @@ EOT config = YAML.dump({ after_script: "bundle update", rspec: { script: "test" } }) expect do GitlabCiYamlProcessor.new(config, path) - end.to raise_error(GitlabCiYamlProcessor::ValidationError, "after_script should be an array of strings") + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "After script config should be an array of strings") end it "returns errors if job after_script parameter is not an array of strings" do diff --git a/spec/lib/gitlab/ci/config/node/factory_spec.rb b/spec/lib/gitlab/ci/config/node/factory_spec.rb index 01a707a6bd4..10462db7699 100644 --- a/spec/lib/gitlab/ci/config/node/factory_spec.rb +++ b/spec/lib/gitlab/ci/config/node/factory_spec.rb @@ -11,7 +11,7 @@ describe Gitlab::Ci::Config::Node::Factory do .with(value: ['ls', 'pwd']) .create! - expect(entry.value).to eq "ls\npwd" + expect(entry.value).to eq ['ls', 'pwd'] end context 'when setting description' do @@ -21,7 +21,7 @@ describe Gitlab::Ci::Config::Node::Factory do .with(description: 'test description') .create! - expect(entry.value).to eq "ls\npwd" + expect(entry.value).to eq ['ls', 'pwd'] expect(entry.description).to eq 'test description' end end diff --git a/spec/lib/gitlab/ci/config/node/global_spec.rb b/spec/lib/gitlab/ci/config/node/global_spec.rb index 7c8ddffc086..84ab1d49d0b 100644 --- a/spec/lib/gitlab/ci/config/node/global_spec.rb +++ b/spec/lib/gitlab/ci/config/node/global_spec.rb @@ -23,7 +23,8 @@ describe Gitlab::Ci::Config::Node::Global do let(:hash) do { before_script: ['ls', 'pwd'], image: 'ruby:2.2', - services: ['postgres:9.1', 'mysql:5.5'] } + services: ['postgres:9.1', 'mysql:5.5'], + after_script: ['make clean'] } end describe '#process!' do @@ -34,7 +35,7 @@ describe Gitlab::Ci::Config::Node::Global do end it 'creates node object for each entry' do - expect(global.nodes.count).to eq 3 + expect(global.nodes.count).to eq 4 end it 'creates node object using valid class' do @@ -71,7 +72,7 @@ describe Gitlab::Ci::Config::Node::Global do describe '#before_script' do it 'returns correct script' do - expect(global.before_script).to eq "ls\npwd" + expect(global.before_script).to eq ['ls', 'pwd'] end end @@ -86,6 +87,12 @@ describe Gitlab::Ci::Config::Node::Global do expect(global.services).to eq ['postgres:9.1', 'mysql:5.5'] end end + + describe '#after_script' do + it 'returns after script' do + expect(global.after_script).to eq ['make clean'] + end + end end end diff --git a/spec/lib/gitlab/ci/config/node/script_spec.rb b/spec/lib/gitlab/ci/config/node/script_spec.rb index 6af6aa15eef..abd43aa1ee9 100644 --- a/spec/lib/gitlab/ci/config/node/script_spec.rb +++ b/spec/lib/gitlab/ci/config/node/script_spec.rb @@ -10,8 +10,8 @@ describe Gitlab::Ci::Config::Node::Script do let(:config) { ['ls', 'pwd'] } describe '#value' do - it 'returns concatenated command' do - expect(entry.value).to eq "ls\npwd" + it 'returns array of strings' do + expect(entry.value).to eq config end end |