class RSpec::Pipeline::PipelineLoader
This class loads the pipeline from a YAML file, also calling required methods to evaluate templates.
Public Class Methods
new(pipeline_name)
click to toggle source
# File lib/rspec/pipeline/pipeline_loader.rb, line 9 def initialize(pipeline_name) @pipeline_name = pipeline_name @template_loader = TemplateLoader.new end
Public Instance Methods
load()
click to toggle source
# File lib/rspec/pipeline/pipeline_loader.rb, line 14 def load pipeline = YAML.load_file(@pipeline_name) pipeline['stages'] = evaluate_stages(pipeline) pipeline['stages'].each do |stage| stage['jobs'] = evaluate_jobs(stage, pipeline) stage['jobs'].each do |job| job['steps'] = evaluate_steps(job, stage, pipeline) end end pipeline end
Private Instance Methods
evaluate_jobs(stage, pipeline)
click to toggle source
# File lib/rspec/pipeline/pipeline_loader.rb, line 44 def evaluate_jobs(stage, pipeline) templated_items = stage['jobs'].map do |item| if item['template'] load_template(item, 'jobs', [stage, pipeline]) else item end end templated_items.flatten.compact end
evaluate_stages(pipeline)
click to toggle source
# File lib/rspec/pipeline/pipeline_loader.rb, line 32 def evaluate_stages(pipeline) templated_items = pipeline['stages'].map do |item| if item['template'] load_template(item, 'stages', [pipeline]) else item end end templated_items.flatten.compact end
evaluate_steps(job, stage, pipeline)
click to toggle source
# File lib/rspec/pipeline/pipeline_loader.rb, line 56 def evaluate_steps(job, stage, pipeline) templated_steps = job['steps'].map do |step| if step['template'] load_template(step, 'steps', [job, stage, pipeline]) else step end end templated_steps.flatten.compact end
load_template(template, type, context)
click to toggle source
# File lib/rspec/pipeline/pipeline_loader.rb, line 68 def load_template(template, type, context) template_name, template_repo = parse_template_metadata(template, context) @template_loader.load(type, template_name, template_repo, template['parameters']) end
parse_template_metadata(template, context)
click to toggle source
# File lib/rspec/pipeline/pipeline_loader.rb, line 74 def parse_template_metadata(template, context) if template['template'].include? '@' template['template'].split '@' else item_with_metadata = context.detect { |item| item['_meta'] && item['_meta']['repo'] } if item_with_metadata [template['template'], item_with_metadata['_meta']['repo']] else [template['template'], '.'] end end end