Class: Pipedream::Start

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Includes:
AwsServices
Defined in:
lib/pipedream/start.rb

Instance Method Summary collapse

Methods included from AwsServices

#cfn, #codepipeline, #s3

Methods included from AwsServices::Helpers

#are_you_sure?, #inferred_pipeline_name, #inferred_stack_name, #pipeline_name_convention, #stack_exists?

Constructor Details

#initialize(options) ⇒ Start

Returns a new instance of Start.



6
7
8
9
10
11
# File 'lib/pipedream/start.rb', line 6

def initialize(options)
  @options = options
  @pipeline_name = options[:pipeline_name] || inferred_pipeline_name
  @full_pipeline_name = pipeline_name_convention(@pipeline_name)
  @stack_name = options[:stack_name] || inferred_stack_name(@pipeline_name)
end

Instance Method Details

#check_pipeline_exists!Object



45
46
47
# File 'lib/pipedream/start.rb', line 45

def check_pipeline_exists!
  pipeline_name
end

#current_pipeline_branchObject

Actual branch on current pipeline



37
38
39
40
41
42
# File 'lib/pipedream/start.rb', line 37

def current_pipeline_branch
  resp = codepipeline.get_pipeline(name: pipeline_name)
  source_stage = resp.pipeline.stages.find { |s| s.name == "Source" }
  action = source_stage.actions.first
  action.configuration['Branch']
end

#different_branch?Boolean

Returns:

  • (Boolean)


31
32
33
34
# File 'lib/pipedream/start.rb', line 31

def different_branch?
  return false unless @options[:branch]
  current_pipeline_branch != @options[:branch]
end

#pipeline_nameObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/pipedream/start.rb', line 49

def pipeline_name
  if pipeline_exists?(@full_pipeline_name)
    @full_pipeline_name
  elsif stack_exists?(@stack_name) # allow `cb start STACK_NAME` to work too
    resp = cfn.describe_stack_resources(stack_name: @stack_name)
    resource = resp.stack_resources.find do |r|
      r.logical_resource_id == "CodePipeline"
    end
    resource.physical_resource_id # pipeline name
  else
    puts "ERROR: Unable to find the pipeline with either full_pipeline_name: #{@full_pipeline_name} or stack name: #{@stack_name}".color(:red)
    exit 1
  end
end

#redeployObject

Pipedreamline does not currently support specifying a different branch starting an execution. Workaround this limitation by updating the pipeline and then starting the execution.



22
23
24
25
26
27
28
29
# File 'lib/pipedream/start.rb', line 22

def redeploy
  return unless different_branch?
  puts "Different branch detected."
  puts "  Current pipeline branch: #{current_pipeline_branch}"
  puts "  Requested branch: #{@options[:branch]}"
  puts "Updating pipeline with new branch.".color(:green)
  Deploy.new(@options).run
end

#runObject



13
14
15
16
17
18
# File 'lib/pipedream/start.rb', line 13

def run
  check_pipeline_exists!
  redeploy
  resp = codepipeline.start_pipeline_execution(name: pipeline_name)
  codepipeline_info(resp.pipeline_execution_id)
end