Import/Export TeamCity build configuration from one server to another
Asked Answered
F

4

32

What's the best way to move a single TeamCity build configuration from one server to another?

I have a local instance of TeamCity that I test builds on. Then when the build is sufficiently mature, I manually create it (eyeball-copy) on our main TeamCity server.

Is there an Export & Import feature that will do this for me?

Frozen answered 22/4, 2014 at 15:40 Comment(1)
There's a step by step guide on their documentation: confluence.jetbrains.com/display/TCD65/…Eulaliaeulaliah
D
37

Unfortunately there is no such thing. TeamCity 8 made the situation a little bit better though by introducing a Build Id format (project name + build config name, can be overwritten) that makes it feasible to "hand copy" build configurations:

Basically under the hood all your TeamCity build configurations are really just XML files in the BuildServer\config\projects\ folder and sub folders. While I haven't tried this you should be able to just copy your project folder or build config XML to the appropriate destination on your new TeamCity instance if the ids don't collide. At the very least you can definitely overwrite existing projects with updates this way (something I have done in the past to dynamically change build configs "on the fly").

Of course if your build config depends on other builds / artifacts those ids have to match as well, so either you have to copy those as well or adjust the ids accordingly. Same goes for agent requirements.

Edit:

With TeamCity 9 out now there's a much better option to move projects between TeamCity servers built in:

Now TeamCity provides the ability to move projects among servers: you can transfer projects with all their data (settings, builds and changes history, etc.) and with your TeamCity user accounts from one server to another. All you need to do is create a usual backup file on the source TeamCity server containing the projects to be imported, put the backup file into the /import directory on the target server and follow the import steps on the Administration | Projects Import page.

For a full summary see what's new in TeamCity 9.

Densimeter answered 22/4, 2014 at 22:6 Comment(0)
A
19

For TeamCity 9 and above:

  1. Make sure both instances of TeamCity are running the same version.
  2. Export data from TeamCity: Using the web UI on the source machine, go to Administration -> Backup and do a Basic backup. It will tell you the path to the backup file created.
  3. Import data to TeamCity:
    1. On the target server, open the web UI and navigate to Administration -> Projects Import. This will tell you the path to the import directory.
    2. Copy the backup file to the import directory, refresh the web UI, and click 'Configure Import Scope'
    3. Select the projects and categories of data you want to import. Given that the question was just about build configurations, you would uncheck importing users and groups. Click 'Start import'.
Adulterant answered 21/10, 2015 at 10:19 Comment(2)
for TC version differences, you can open up the ZIP file generated from the export and change the fields in the version.txt to match the TC Version you are importing to.Lanta
@Lanta Sounds like kamikaze to me.Overcapitalize
O
2

TeamCity 9 has this ability builtin - https://confluence.jetbrains.com/display/TCD9/Projects+Import

Ordinal answered 7/9, 2015 at 10:1 Comment(0)
L
1

I found that the projects import function wasn't granular enough to restore just one build configuration, but managed to do this through the API. Using PowerShell you can call an invoke-webrequest against the source:

$serviceAccountCredentials = New-Object System.Management.Automation.PSCredential -ArgumentList @('<domain>\<user>',(ConvertTo-SecureString -String 'Password' -AsPlainText -Force))

$settings = Invoke-RestMethod -Method Get -Uri 'http://<TeamCity_Build_server>/httpAuth/app/rest/buildTypes/id:<buildID>/settings' -Credential $serviceAccountCredentials
$parameters = Invoke-RestMethod -Method Get -Uri 'http://<TeamCity_Build_server>/httpAuth/app/rest/buildTypes/id:<buildID>/parameters' -Credential $serviceAccountCredentials
$steps = Invoke-RestMethod -Method Get -Uri 'http://<TeamCity_Build_server>/httpAuth/app/rest/buildTypes/id:<buildID>/steps' -Credential $serviceAccountCredentials
$features = Invoke-RestMethod -Method Get -Uri 'http://<TeamCity_Build_server>/httpAuth/app/rest/buildTypes/id:<buildID>/features' -Credential $serviceAccountCredentials
$triggers = Invoke-RestMethod -Method Get -Uri 'http://<TeamCity_Build_server>/httpAuth/app/rest/buildTypes/id:<buildID>/triggers' -Credential $serviceAccountCredentials
$agentReqs = Invoke-RestMethod -Method Get -Uri 'http://<TeamCity_Build_server>/httpAuth/app/rest/buildTypes/id:<buildID>/agent-requirements' -Credential $serviceAccountCredentials
$artifactDep = Invoke-RestMethod -Method Get -Uri 'http://<TeamCity_Build_server>/httpAuth/app/rest/buildTypes/id:<buildID>/artifact-dependencies' -Credential $serviceAccountCredentials
$snapshotDep = Invoke-RestMethod -Method Get -Uri 'http://<TeamCity_Build_server>/httpAuth/app/rest/buildTypes/id:<buildID>/snapshot-dependencies' -Credential $serviceAccountCredentials
$vcsRoot = Invoke-RestMethod -Method Get -Uri 'http://<TeamCity_Build_server>/httpAuth/app/rest/buildTypes/id:<buildID>/vcs-root-entries' -Credential $serviceAccountCredentials

You can then pass the XML through to the destination:

#import settings
Invoke-RestMethod -Method put -Uri 'http://<TeamCity_Build_server>/httpAuth/app/rest/buildTypes/id:<buildID>/settings' -body $settings.OuterXml -ContentType application/xml -Credential $serviceAccountCredentials
#import parameters
Invoke-RestMethod -Method put -Uri 'http://<TeamCity_Build_server>/httpAuth/app/rest/buildTypes/id:<buildID>/parameters' -body $parameters.OuterXml -ContentType application/xml -Credential $serviceAccountCredentials
#import steps
Invoke-RestMethod -Method put -Uri 'http://<TeamCity_Build_server>/httpAuth/app/rest/buildTypes/id:<buildID>/steps' -body $steps.OuterXml -ContentType application/xml -Credential $serviceAccountCredentials
#import features
Invoke-RestMethod -Method put -Uri 'http://<TeamCity_Build_server>/httpAuth/app/rest/buildTypes/id:<buildID>/features' -body $features.OuterXml -ContentType application/xml -Credential $serviceAccountCredentials
#import triggers
Invoke-RestMethod -Method put -Uri 'http://<TeamCity_Build_server>/httpAuth/app/rest/buildTypes/id:<buildID>/triggers' -body $triggers.OuterXml -ContentType application/xml -Credential $serviceAccountCredentials
#Import VCS root setting
Invoke-RestMethod -Method put -Uri 'http://<TeamCity_Build_server>/httpAuth/app/rest/buildTypes/id:<buildID>/vcs-root-entries' -body $VCSRoots.OuterXml -ContentType application/xml -Credential $serviceAccountCredentials

The TeamCity api documentation about build configurations is available here: https://confluence.jetbrains.com/display/TW/REST+API#RESTAPI-BuildConfigurationAndTemplateSettings

Lockjaw answered 10/6, 2019 at 12:14 Comment(1)
"confluence.jetbrains.com no longer hosts public data." :/Overcapitalize

© 2022 - 2024 — McMap. All rights reserved.