我尝试通过PowerShell和TeamCity 8 REST API以自动方式向构建配置添加构建触发器。
使用以下问题作为参考,似乎我可以做的是:Adding a Trigger to a build configuration in TeamCity using the REST API
但是,每当我尝试使用以下代码将触发器添加到构建时,我都会收到(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成功实现了这个?
答案 0 :(得分: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。