Class: Ci::GitlabCiYamlProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/ci/gitlab_ci_yaml_processor.rb

Defined Under Namespace

Classes: ValidationError

Constant Summary collapse

DEFAULT_STAGES =
%w(build test deploy)
DEFAULT_STAGE =
'test'
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, :before_script, :after_script, :variables]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, path = nil) ⇒ GitlabCiYamlProcessor

Returns a new instance of GitlabCiYamlProcessor


14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ci/gitlab_ci_yaml_processor.rb', line 14

def initialize(config, path = nil)
  @config = YAML.safe_load(config, [Symbol], [], true)
  @path = path

  unless @config.is_a? Hash
    raise ValidationError, "YAML should be a hash"
  end

  @config = @config.deep_symbolize_keys

  initial_parsing

  validate!
end

Instance Attribute Details

#after_scriptObject (readonly)

Returns the value of attribute after_script


12
13
14
# File 'lib/ci/gitlab_ci_yaml_processor.rb', line 12

def after_script
  @after_script
end

#before_scriptObject (readonly)

Returns the value of attribute before_script


12
13
14
# File 'lib/ci/gitlab_ci_yaml_processor.rb', line 12

def before_script
  @before_script
end

#cacheObject (readonly)

Returns the value of attribute cache


12
13
14
# File 'lib/ci/gitlab_ci_yaml_processor.rb', line 12

def cache
  @cache
end

#imageObject (readonly)

Returns the value of attribute image


12
13
14
# File 'lib/ci/gitlab_ci_yaml_processor.rb', line 12

def image
  @image
end

#pathObject (readonly)

Returns the value of attribute path


12
13
14
# File 'lib/ci/gitlab_ci_yaml_processor.rb', line 12

def path
  @path
end

#servicesObject (readonly)

Returns the value of attribute services


12
13
14
# File 'lib/ci/gitlab_ci_yaml_processor.rb', line 12

def services
  @services
end

Instance Method Details

#buildsObject


33
34
35
36
37
# File 'lib/ci/gitlab_ci_yaml_processor.rb', line 33

def builds
  @jobs.map do |name, job|
    build_job(name, job)
  end
end

#builds_for_stage_and_ref(stage, ref, tag = false, trigger_request = nil) ⇒ Object


29
30
31
# File 'lib/ci/gitlab_ci_yaml_processor.rb', line 29

def builds_for_stage_and_ref(stage, ref, tag = false, trigger_request = nil)
  builds.select{|build| build[:stage] == stage && process?(build[:only], build[:except], ref, tag, trigger_request)}
end

#global_variablesObject


43
44
45
# File 'lib/ci/gitlab_ci_yaml_processor.rb', line 43

def global_variables
  @variables
end

#job_variables(name) ⇒ Object


47
48
49
50
51
52
# File 'lib/ci/gitlab_ci_yaml_processor.rb', line 47

def job_variables(name)
  job = @jobs[name.to_sym]
  return [] unless job

  job.fetch(:variables, [])
end

#stagesObject


39
40
41
# File 'lib/ci/gitlab_ci_yaml_processor.rb', line 39

def stages
  @stages || DEFAULT_STAGES
end