class Buildkiq::Job
Attributes
build[R]
environments[R]
logger[R]
project_name[R]
Public Class Methods
new(project_name:, environments:, logger: Logger.new(STDOUT))
click to toggle source
# File lib/buildkiq/job.rb, line 8 def initialize(project_name:, environments:, logger: Logger.new(STDOUT)) @client = Aws::CodeBuild::Client.new @project_name = project_name @environments = environments @logger = logger end
Public Instance Methods
artifact()
click to toggle source
# File lib/buildkiq/job.rb, line 59 def artifact @artifact ||= Artifact.new(self) end
artifact_upload_success?()
click to toggle source
# File lib/buildkiq/job.rb, line 49 def artifact_upload_success? !fetch_build.phases.select { |v| v.phase_type == "UPLOAD_ARTIFACTS" && v.phase_status == "SUCCEEDED" }.empty? end
build_url()
click to toggle source
# File lib/buildkiq/job.rb, line 41 def build_url "https://#{@client.config.region}.console.aws.amazon.com/codebuild/home#/builds/#{build[:id]}/view/new" end
project()
click to toggle source
# File lib/buildkiq/job.rb, line 55 def project @project ||= @client.batch_get_projects(names: [project_name])[0][0] end
start(source_version: nil, build_cmd: nil)
click to toggle source
# File lib/buildkiq/job.rb, line 15 def start(source_version: nil, build_cmd: nil) params = {project_name: project_name, environment_variables_override: environments} if source_version && source_type == "S3" raise ArgumentError.new("source_version parameter can not be used, project source type is S3") end params[:source_version] = source_version if source_version params[:buildspec_override] = build_spec(build_cmd) if build_cmd logger.info("build parameter: #{params}") @build = @client.start_build(params).build end
status()
click to toggle source
# File lib/buildkiq/job.rb, line 37 def status fetch_build.build_status end
wait_for_job(timeout_sec: build.timeout_in_minutes * 60, sleep_sec: 5)
click to toggle source
# File lib/buildkiq/job.rb, line 29 def wait_for_job(timeout_sec: build.timeout_in_minutes * 60, sleep_sec: 5) Timeout.timeout(timeout_sec) do sleep(sleep_sec) until done? end self end
watch_log_url()
click to toggle source
# File lib/buildkiq/job.rb, line 45 def watch_log_url build.logs.deep_link if build end
Private Instance Methods
build_spec(cmd)
click to toggle source
# File lib/buildkiq/job.rb, line 77 def build_spec(cmd) <<~EOS version: 0.2 phases: build: commands: - #{cmd} EOS end
done?()
click to toggle source
# File lib/buildkiq/job.rb, line 73 def done? fetch_build.build_complete end
fetch_build()
click to toggle source
# File lib/buildkiq/job.rb, line 65 def fetch_build @build = @client.batch_get_builds(ids: [build[:id]]).builds[0] end
source_type()
click to toggle source
# File lib/buildkiq/job.rb, line 69 def source_type project.source.type end