Class: Putpaws::CodeBuild::ProjectCommand
- Inherits:
-
Object
- Object
- Putpaws::CodeBuild::ProjectCommand
- Defined in:
- lib/putpaws/code_build/project_command.rb
Instance Attribute Summary collapse
-
#codebuild_client ⇒ Object
readonly
Returns the value of attribute codebuild_client.
-
#codebuild_project ⇒ Object
Returns the value of attribute codebuild_project.
-
#project_name_prefix ⇒ Object
readonly
Returns the value of attribute project_name_prefix.
-
#region ⇒ Object
readonly
Returns the value of attribute region.
Class Method Summary collapse
Instance Method Summary collapse
- #build_source_version(type:, version:) ⇒ Object
-
#initialize(region:, project_name_prefix: nil) ⇒ ProjectCommand
constructor
A new instance of ProjectCommand.
- #list_codebuild_projects ⇒ Object
- #start_build_with_specific_version(source_version:, environment_variables: {}, buildspec_override: nil, artifacts_override: nil) ⇒ Object
Constructor Details
#initialize(region:, project_name_prefix: nil) ⇒ ProjectCommand
Returns a new instance of ProjectCommand.
13 14 15 16 17 18 |
# File 'lib/putpaws/code_build/project_command.rb', line 13 def initialize(region:, project_name_prefix: nil) @codebuild_client = Aws::CodeBuild::Client.new({region: region}) @region = region @project_name_prefix = project_name_prefix @codebuild_project = nil end |
Instance Attribute Details
#codebuild_client ⇒ Object (readonly)
Returns the value of attribute codebuild_client.
10 11 12 |
# File 'lib/putpaws/code_build/project_command.rb', line 10 def codebuild_client @codebuild_client end |
#codebuild_project ⇒ Object
Returns the value of attribute codebuild_project.
12 13 14 |
# File 'lib/putpaws/code_build/project_command.rb', line 12 def codebuild_project @codebuild_project end |
#project_name_prefix ⇒ Object (readonly)
Returns the value of attribute project_name_prefix.
11 12 13 |
# File 'lib/putpaws/code_build/project_command.rb', line 11 def project_name_prefix @project_name_prefix end |
#region ⇒ Object (readonly)
Returns the value of attribute region.
11 12 13 |
# File 'lib/putpaws/code_build/project_command.rb', line 11 def region @region end |
Class Method Details
.config(config) ⇒ Object
6 7 8 |
# File 'lib/putpaws/code_build/project_command.rb', line 6 def self.config(config) new(**config.codebuild_command_params) end |
Instance Method Details
#build_source_version(type:, version:) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/putpaws/code_build/project_command.rb', line 44 def build_source_version(type:, version:) type = type.to_sym if type == :branch "refs/heads/#{version}" elsif type == :tag "refs/tags/#{version}" elsif type == :commit_id version else raise "Please specify valid type: branch or tag or commit_id" end end |
#list_codebuild_projects ⇒ Object
20 21 22 23 |
# File 'lib/putpaws/code_build/project_command.rb', line 20 def list_codebuild_projects res = codebuild_client.batch_get_projects(names: [project_name_prefix]) res.projects.select{|pr| pr.name.start_with?(project_name_prefix)} end |
#start_build_with_specific_version(source_version:, environment_variables: {}, buildspec_override: nil, artifacts_override: nil) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/putpaws/code_build/project_command.rb', line 25 def start_build_with_specific_version(source_version:, environment_variables: {}, buildspec_override: nil, artifacts_override: nil) current_variables = codebuild_project.environment.environment_variables.map{|x| [x.name, {type: x.type, value: x.value}]}.to_h new_variables = environment_variables.reduce(current_variables) {|acc,(k,v)| acc[k] = {type: 'PLANTTEXT', value: v}} environment_variables_override = new_variables.map{|k,v| v.merge(name: k)} params = { project_name: codebuild_project.name, source_version: source_version, environment_variables_override: environment_variables_override, } if buildspec_override params = params.merge(buildspec_override: buildspec_override) end if artifacts_override params = params.merge(artifacts_override: artifacts_override) end codebuild_client.start_build(**params) end |