如何将单个TeamCity构建配置从一个服务器移动到另一个服务器?
我在本地实例上测试构建。当构建足够成熟时,我会手动在我们的主要TeamCity服务器上创建它。
是否有导入和导出功能可以帮助我完成此操作?
如何将单个TeamCity构建配置从一个服务器移动到另一个服务器?
我在本地实例上测试构建。当构建足够成熟时,我会手动在我们的主要TeamCity服务器上创建它。
是否有导入和导出功能可以帮助我完成此操作?
编辑:
现在,随着TeamCity 9的推出,有一个更好的选项来在TeamCity服务器之间移动项目:
现在,TeamCity提供了在服务器之间移动项目的能力:您可以将包含所有数据(设置、构建和更改历史记录等)以及TeamCity用户帐户的项目从一个服务器转移到另一个服务器。您需要做的就是在源TeamCity服务器上创建一个常规备份文件,其中包含要导入的项目,将备份文件放入目标服务器上的/import目录中,并按照管理|项目导入页面上的导入步骤进行操作。对于 TeamCity 9 及以上版本:
Administration -> Backup
并进行基本备份。它会告诉您创建备份文件的路径。Administration -> Projects Import
。这将告诉您导入目录的路径。我发现项目导入功能不够细粒度,无法恢复单个构建配置,但是通过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