从一个服务器导入/导出TeamCity构建配置到另一台服务器

32

如何将单个TeamCity构建配置从一个服务器移动到另一个服务器?

我在本地实例上测试构建。当构建足够成熟时,我会手动在我们的主要TeamCity服务器上创建它。

是否有导入和导出功能可以帮助我完成此操作?


他们的文档中有一份逐步指南:http://confluence.jetbrains.com/display/TCD65/How+To...#HowTo...-copyserver - Gene
4个回答

37
很遗憾,没有这样的功能。然而,TeamCity 8通过引入Build Id格式(项目名称+构建配置名称,可被覆盖)使情况有所改善,从而使“手动复制”构建配置成为可能。基本上,在幕后,所有的TeamCity构建配置都是在BuildServer\config\projects\文件夹及其子文件夹中的XML文件。虽然我没有尝试过,但如果ID不冲突,你应该能够将项目文件夹或构建配置XML直接复制到新的TeamCity实例的适当目标位置。至少,你可以以这种方式覆盖现有的项目进行更新(这是我过去动态更改构建配置的方法之一)。当然,如果你的构建配置依赖于其他构建/工件,那么这些ID也必须匹配,因此你必须复制它们或相应地调整ID。代理要求也是如此。

编辑:

现在,随着TeamCity 9的推出,有一个更好的选项来在TeamCity服务器之间移动项目:

现在,TeamCity提供了在服务器之间移动项目的能力:您可以将包含所有数据(设置、构建和更改历史记录等)以及TeamCity用户帐户的项目从一个服务器转移到另一个服务器。您需要做的就是在源TeamCity服务器上创建一个常规备份文件,其中包含要导入的项目,将备份文件放入目标服务器上的/import目录中,并按照管理|项目导入页面上的导入步骤进行操作。
有关详细信息,请参阅TeamCity 9的新功能的完整摘要。

19

对于 TeamCity 9 及以上版本:

  1. 确保两个 TeamCity 的实例运行相同的版本。
  2. 从 TeamCity 导出数据:在源计算机上使用 web UI,进入 Administration -> Backup 并进行基本备份。它会告诉您创建备份文件的路径。
  3. 将数据导入 TeamCity
    1. 在目标服务器上打开 web UI,并导航到 Administration -> Projects Import。这将告诉您导入目录的路径。
    2. 将备份文件复制到导入目录中,刷新 web UI,并点击“配置导入范围”
    3. 选择要导入的项目和数据类别。考虑到问题只涉及构建配置,您应该取消选中用户和组的导入。单击“开始导入”。

3
针对TC版本差异,您可以打开从导出生成的ZIP文件,并更改version.txt中的字段以匹配您要导入的TC版本。 - dannash918
@dannash918 这听起来对我来说就像是神风特攻队。 - The incredible Jan


1

我发现项目导入功能不够细粒度,无法恢复单个构建配置,但是通过API可以实现。使用PowerShell,您可以针对源调用invoke-webrequest:

$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

然后,您可以将XML传递到目标位置:

#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

关于构建配置的TeamCity API文档可以在这里找到:https://confluence.jetbrains.com/display/TW/REST+API#RESTAPI-BuildConfigurationAndTemplateSettings


confluence.jetbrains.com不再托管公共数据。:/ - The incredible Jan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接