将单个TeamCity构建配置从一个服务器移动到另一个服务器的最佳方法是什么?
我有一个我测试构建的TeamCity的本地实例。然后,当构建足够成熟时,我在我们的主TeamCity服务器上手动创建它(眼球副本)。
是否有出口&导入功能将为我这样做?
答案 0 :(得分:36)
不幸的是没有这样的事情。 TeamCity 8通过引入Build Id格式(项目名称+构建配置名称,可以覆盖)使得“手动复制”构建配置成为可能,使情况变得更好:
基本上,所有TeamCity构建配置都只是BuildServer \ config \ projects \文件夹和子文件夹中的XML文件。虽然我没有尝试过这个,但是如果id不冲突,你应该只能复制项目文件夹或将配置XML构建到新TeamCity实例的相应目的地。至少你绝对可以用这种方式覆盖现有的项目(过去我曾经做过的动态改变构建配置的东西)。
当然,如果您的构建配置依赖于其他构建/工件,那些ID也必须匹配,因此您要么必须复制它们,要么相应地调整ID。代理商要求也是如此。
修改强>
现在有了TeamCity 9,在内置的TeamCity服务器之间移动项目有了更好的选择:
现在,TeamCity提供了在服务器之间移动项目的能力:你 可以传输项目及其所有数据(设置,构建和 更改历史记录等)以及您的TeamCity用户帐户 服务器到另一个。您需要做的就是创建一个通常的备份文件 源TeamCity服务器包含要导入的项目,put 将备份文件放入/ import目录中 目标服务器并按照管理|上的导入步骤进行操作 项目导入页面。
有关完整摘要,请参阅what's new in TeamCity 9。
答案 1 :(得分:14)
对于TeamCity 9及以上版本:
Administration -> Backup
并执行基本备份。它会告诉您创建的备份文件的路径。Administration -> Projects Import
。这将告诉您导入目录的路径。答案 2 :(得分:2)
TeamCity 9具有内置的这种能力 - https://confluence.jetbrains.com/display/TCD9/Projects+Import
答案 3 :(得分:0)
我发现项目导入功能不够精细,无法仅还原一个构建配置,但是可以通过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