Module: TeamCity::Client::Builds
- Defined in:
- lib/sambot/teamcity/builds.rb
Constant Summary collapse
- LINUX_WRAPPER_COOKBOOKS_PROJECT =
'Wrapper Cookbooks - GCP'
- LINUX_ROLE_COOKBOOKS_PROJECT =
'Role Cookbooks - GCP'
- GCP_PROJECT =
'Google Cloud Platform'
Instance Method Summary collapse
- #attach_template(build_id, template_id) ⇒ Object
- #build_exists?(project, build_name) ⇒ Boolean
- #create_build(project_id, name) ⇒ Object
- #create_cookbook_build(config) ⇒ Object
Instance Method Details
#attach_template(build_id, template_id) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/sambot/teamcity/builds.rb', line 9 def attach_template(build_id, template_id) path = "buildTypes/#{build_id}/template" put(path, :content_type => :text) do |request| request.body = template_id end end |
#build_exists?(project, build_name) ⇒ Boolean
24 25 26 27 |
# File 'lib/sambot/teamcity/builds.rb', line 24 def build_exists?(project, build_name) all_builds = TeamCity.project_buildtypes(id: project.id).map {|x| x.name} all_builds.include?(build_name) end |
#create_build(project_id, name) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/sambot/teamcity/builds.rb', line 16 def create_build(project_id, name) path = "projects/#{project_id}/buildTypes" payload = { name: name } post(path, :content_type => :json, :accept => :json) do |request| request.body = payload.to_json end end |
#create_cookbook_build(config) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/sambot/teamcity/builds.rb', line 29 def create_cookbook_build(config) ::TeamCity.configure do |config| config.endpoint = 'https://teamcity.brighter.io/httpAuth/app/rest' || ENV['TEAMCITY_URL'] config.http_user = ENV['TEAMCITY_USERNAME'] config.http_password = ENV['TEAMCITY_PASSWORD'] end project_name = config.is_role_cookbook? ? LINUX_ROLE_COOKBOOKS_PROJECT : LINUX_WRAPPER_COOKBOOKS_PROJECT ::Sambot::UI.debug("Looking for the project #{project_name}") project = ::TeamCity.find_project_by_name(project_name) if build_exists?(project, config.name) ::Sambot::UI.info("The build configuration '#{config.name}' already exists in the project '#{project.name}'") else ::Sambot::UI.debug("Looking for the template project #{GCP_PROJECT}") template_project = ::TeamCity.find_project_by_name(GCP_PROJECT) template = ::TeamCity.project_templates(id: template_project.id)[0] ::Sambot::UI.debug("Using the TeamCity template #{template.name}") build_configuration = ::TeamCity.create_build(project.id, config.name) ::TeamCity.attach_template(build_configuration.id, template.id) ::Sambot::UI.info("The build configuration '#{config.name}' has been created in the project '#{project.name}'") build_configuration end end |