0

PowerShell と TeamCity 8 REST API を使用して、自動化された方法でビルド トリガーをビルド構成に追加しようとしています。

次の質問を参照として使用すると、私がやろうとしていることが可能であるように見えます: REST API を使用して TeamCity のビルド構成にトリガーを追加する

しかし、次のコードを使用してトリガーをビルドに追加しようとすると、(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 を使用してこれを正常に実装した人はいますか?

4

1 に答える 1

2

その 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-RestMethodPowershell v4 です。

于 2015-01-21T13:17:39.937 に答える