Skip to content

Instantly share code, notes, and snippets.

@sclausson
Last active March 14, 2016 09:20
Show Gist options
  • Save sclausson/7bbe9a025575a482a187 to your computer and use it in GitHub Desktop.
Save sclausson/7bbe9a025575a482a187 to your computer and use it in GitHub Desktop.
require 'teamcity'
tc_server = '192.168.99.100'
tc_port = 8111
tc_rest_url = "http://#{tc_server}:#{tc_port}/httpAuth/app/rest"
tc_user = 'teamcity'
tc_pass = 'password'
#configure connection
TeamCity.configure do |c|
c.endpoint = tc_rest_url
c.http_user = tc_user
c.http_password = tc_pass
end
#create project
project_name = 'test-project'
test_project = TeamCity.create_project(project_name)
#create build configuration
build_config_name = 'test-build-config'
test_buildtype = TeamCity.create_buildtype(project_name, build_config_name)
#set buildtype setting
TeamCity.set_buildtype_setting(test_buildtype.id, 'buildNumberPattern', 'test-%build.counter%')
#set buildtype parameter
TeamCity.set_buildtype_parameter(test_buildtype.id, 'test-parameter', 'foo')
#create build trigger
TeamCity.create_build_trigger(test_buildtype.id, type: 'vcsTrigger', name: 'every checkin') do |properties|
properties['groupCheckinsByCommitter'] = 'true'
properties['perCheckinTriggering'] = 'true'
properties['quietPeriodMode'] = 'DO_NOT_USE'
end
#create vcs root
vcs_root_name = 'test-git-vcs-root'
vcs_url = 'git@github.com:sclausson/a4tp-docker.git'
test_vcs_root = TeamCity.create_vcs_root(vcs_name: vcs_root_name, vcs_type: 'git', :project_id => project_name) do |properties|
properties['branch'] = 'master'
properties['url'] = vcs_url
properties['authMethod'] = 'PRIVATE_KEY_DEFAULT'
properties['ignoreKnownHosts'] = true
end
#attach vcs root to build configuration
TeamCity.attach_vcs_root(test_buildtype.id, test_vcs_root.id)
#create build step
build_step_name = 'test-build-step'
build_step_type = 'simpleRunner'
test_build_step = TeamCity.create_build_step(test_buildtype.id, :type => build_step_type, :name => build_step_name) do |properties|
properties['script.content'] = "#! /bin/sh\necho 'hello world!'"
properties['use.custom.script'] = 'true'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment