2015-01-21 40 views
0

我试图通过PowerShell和TeamCity 8 REST API以自动方式将构建触发器添加到构建配置中。添加触发器通过REST API和PowerShell在TeamCity中构建配置

使用以下问题作为参考,它会出现什么,我试图做的是可能的:Adding a Trigger to a build configuration in TeamCity using the REST API

但是,每当我试图触发添加到构建,使用下面的代码,我得到a (405) Method Not Allowed错误:

$triggerXML= "<trigger id=`"TriggerID`" type=`"buildDependencyTrigger`"> 
        <properties> 
         <property name=`"afterSuccessfulBuildOnly`" value=`"true`"/> 
         <property name=`"dependsOn`" value=`"BuildID`"/> 
        </properties> 
       </trigger>" 

$webclient.UploadString('http://teamcity:8111/httpAuth/app/rest/buildTypes/BuildID', "POST", $triggerXML) 

有没有人使用PowerShell成功实现了这个功能?

回答

1

不是那个API,但我有使TeamCity自动化的脚本。

下面的代码片段使用:

$TeamCityHostAndPort = "myteamcityserver:8111" 

# authenticate with NTLM 
$LoginUrl = "http://$TeamCityHostAndPort/ntlmLogin.html" 
Invoke-WebRequest -Uri $LoginUrl -UseDefaultCredentials -SessionVariable TeamCitySession | Out-Null 

#start backup 
$StartBackupUrl = "http://$TeamCityHostAndPort/httpAuth/app/rest/server/backup?includeConfigs=true&includeDatabase=true&includeBuildLogs=true&fileName=TeamCity_Backup_" 
$filename = Invoke-RestMethod -WebSession $TeamCitySession -Method Post -Uri $StartBackupUrl 

通知第一次调用进行身份验证(我禁用内置的用户和使用Windows身份验证棒),并传递给后续调用验证会话。 Invoke-RestMethod是Powershell v4。

+0

该片段看起来像是自动创建TeamCity的备份。我正在寻找构建触发器分配的自动化 – ShaneC 2015-01-21 14:09:15

+0

您是否尝试过使用PUT动词而不是POST? – 2015-01-21 14:25:19

+0

我有,相同的结果。如果它没有实现,我不会感到惊讶,这只是我能够找到某人(在我的问题中提到)谁声称已经完成了我想用其他语言做的事情 – ShaneC 2015-01-21 14:38:25

相关问题