summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-07-18 14:15:01 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-07-18 15:21:53 +0200
commit24b686ebb64e2f5a02d812e9aa726f1ba0868c2e (patch)
tree1b467db7de06d95bc5a4d19664b4468dd58badf7 /lib
parent47fa9f33ca552e085df2158db41b614a79f3651f (diff)
downloadgitlab-ce-24b686ebb64e2f5a02d812e9aa726f1ba0868c2e.tar.gz
Move job artifacts configuration new CI config code
Diffstat (limited to 'lib')
-rw-r--r--lib/ci/gitlab_ci_yaml_processor.rb20
-rw-r--r--lib/gitlab/ci/config/node/artifacts.rb32
-rw-r--r--lib/gitlab/ci/config/node/attributable.rb23
-rw-r--r--lib/gitlab/ci/config/node/job.rb7
-rw-r--r--lib/gitlab/ci/config/node/validators.rb10
5 files changed, 71 insertions, 21 deletions
diff --git a/lib/ci/gitlab_ci_yaml_processor.rb b/lib/ci/gitlab_ci_yaml_processor.rb
index 7306fd110bd..ec85cf1bd3d 100644
--- a/lib/ci/gitlab_ci_yaml_processor.rb
+++ b/lib/ci/gitlab_ci_yaml_processor.rb
@@ -148,26 +148,6 @@ module Ci
raise ValidationError, "#{name} job: artifacts unknown parameter #{key}"
end
end
-
- if job[:artifacts][:name] && !validate_string(job[:artifacts][:name])
- raise ValidationError, "#{name} job: artifacts:name parameter should be a string"
- end
-
- if job[:artifacts][:untracked] && !validate_boolean(job[:artifacts][:untracked])
- raise ValidationError, "#{name} job: artifacts:untracked parameter should be an boolean"
- end
-
- if job[:artifacts][:paths] && !validate_array_of_strings(job[:artifacts][:paths])
- raise ValidationError, "#{name} job: artifacts:paths parameter should be an array of strings"
- end
-
- if job[:artifacts][:when] && !job[:artifacts][:when].in?(%w[on_success on_failure always])
- raise ValidationError, "#{name} job: artifacts:when parameter should be on_success, on_failure or always"
- end
-
- if job[:artifacts][:expire_in] && !validate_duration(job[:artifacts][:expire_in])
- raise ValidationError, "#{name} job: artifacts:expire_in parameter should be a duration"
- end
end
def validate_job_dependencies!(name, job)
diff --git a/lib/gitlab/ci/config/node/artifacts.rb b/lib/gitlab/ci/config/node/artifacts.rb
new file mode 100644
index 00000000000..7b3eb7e1992
--- /dev/null
+++ b/lib/gitlab/ci/config/node/artifacts.rb
@@ -0,0 +1,32 @@
+module Gitlab
+ module Ci
+ class Config
+ module Node
+ ##
+ # Entry that represents a configuration of job artifacts.
+ #
+ class Artifacts < Entry
+ include Validatable
+ include Attributable
+
+ attributes :name, :untracked, :paths, :when, :expire_in
+
+ validations do
+ validates :config, type: Hash
+
+ with_options allow_nil: true do
+ validates :name, type: String
+ validates :untracked, boolean: true
+ validates :paths, array_of_strings: true
+ validates :when,
+ inclusion: { in: %w[on_success on_failure always],
+ message: 'should be on_success, on_failure ' \
+ 'or always' }
+ validates :expire_in, duration: true
+ end
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/ci/config/node/attributable.rb b/lib/gitlab/ci/config/node/attributable.rb
new file mode 100644
index 00000000000..6e935c025e4
--- /dev/null
+++ b/lib/gitlab/ci/config/node/attributable.rb
@@ -0,0 +1,23 @@
+module Gitlab
+ module Ci
+ class Config
+ module Node
+ module Attributable
+ extend ActiveSupport::Concern
+
+ class_methods do
+ def attributes(*attributes)
+ attributes.each do |attribute|
+ define_method(attribute) do
+ return unless config.is_a?(Hash)
+
+ config[attribute]
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/ci/config/node/job.rb b/lib/gitlab/ci/config/node/job.rb
index d2113556a08..a6d7f16769c 100644
--- a/lib/gitlab/ci/config/node/job.rb
+++ b/lib/gitlab/ci/config/node/job.rb
@@ -47,8 +47,12 @@ module Gitlab
node :variables, Variables,
description: 'Environment variables available for this job.'
+ node :artifacts, Artifacts,
+ description: 'Artifacts configuration for this job.'
+
helpers :before_script, :script, :stage, :type, :after_script,
- :cache, :image, :services, :only, :except, :variables
+ :cache, :image, :services, :only, :except, :variables,
+ :artifacts
def name
@metadata[:name]
@@ -71,6 +75,7 @@ module Gitlab
only: only,
except: except,
variables: variables_defined? ? variables : nil,
+ artifacts: artifacts,
after_script: after_script }
end
diff --git a/lib/gitlab/ci/config/node/validators.rb b/lib/gitlab/ci/config/node/validators.rb
index d33b407af68..5568be80166 100644
--- a/lib/gitlab/ci/config/node/validators.rb
+++ b/lib/gitlab/ci/config/node/validators.rb
@@ -33,6 +33,16 @@ module Gitlab
end
end
+ class DurationValidator < ActiveModel::EachValidator
+ include LegacyValidationHelpers
+
+ def validate_each(record, attribute, value)
+ unless validate_duration(value)
+ record.errors.add(attribute, 'should be a duration')
+ end
+ end
+ end
+
class RequiredValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
if value.nil?