class Pipedream::Start

Public Class Methods

new(options) click to toggle source
# 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

Public Instance Methods

check_pipeline_exists!() click to toggle source
# File lib/pipedream/start.rb, line 45
def check_pipeline_exists!
  pipeline_name
end
current_pipeline_branch() click to toggle source

Actual branch on current pipeline

# 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?() click to toggle source
# File lib/pipedream/start.rb, line 31
def different_branch?
  return false unless @options[:branch]
  current_pipeline_branch != @options[:branch]
end
pipeline_name() click to toggle source
# 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
redeploy() click to toggle source

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

# 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
run() click to toggle source
# 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

Private Instance Methods

codepipeline_info(execution_id) click to toggle source
# File lib/pipedream/start.rb, line 66
def codepipeline_info(execution_id)
  region = `aws configure get region`.strip rescue "us-east-1"
  url = "https://#{region}.console.aws.amazon.com/codesuite/codepipeline/pipelines/#{pipeline_name}/view"

  puts "Pipeline started: #{pipeline_name}"
  puts "Please check the CodePipeline console for the status."
  puts "CodePipeline Console: #{url}"
  puts "Pipeline cli commands:"
  puts
  puts "    aws codepipeline get-pipeline-execution --pipeline-execution-id #{execution_id} --pipeline-name #{pipeline_name}"
  puts "    aws codepipeline get-pipeline-state --name #{pipeline_name}"
  puts
end
pipeline_exists?(name) click to toggle source
# File lib/pipedream/start.rb, line 80
def pipeline_exists?(name)
  codepipeline.get_pipeline(name: name)
  true
rescue Aws::CodePipeline::Errors::PipelineNotFoundException
  false
end