У меня есть сценарий PowerShell, который вызывает REST API TeamCity для создания резервной копии.
Этот скрипт работал, работал на v7.1, но когда я обновился до 8.0.5, скрипт перестал работать.
Скрипт:
$ErrorActionPreference = 'Stop'
function Execute-HTTPPostCommand()
{
param(
[string] $url
)
$webRequest = [System.Net.WebRequest]::Create($url)
$webRequest.ContentType = "text/html"
$PostStr = [System.Text.Encoding]::Default.GetBytes("")
$webrequest.ContentLength = $PostStr.Length
$webrequest.AuthenticationLevel = [System.Net.Security.AuthenticationLevel]::MutualAuthRequested
$webrequest.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
$webRequest.Method = "POST"
$requestStream = $webRequest.GetRequestStream()
$requestStream.Write($PostStr, 0, $PostStr.length)
$requestStream.Close()
[System.Net.WebResponse] $resp = $webRequest.GetResponse();
$rs = $resp.GetResponseStream();
[System.IO.StreamReader] $sr = New-Object System.IO.StreamReader -argumentList $rs;
[string] $results = $sr.ReadToEnd();
return $results;
}
function Execute-TeamCityBackup()
{
param(
[string] $server,
[string] $addTimestamp,
[string] $includeConfigs,
[string] $includeDatabase,
[string] $includeBuildLogs,
[string] $includePersonalChanges,
[string] $fileName
)
$TeamCityURL = [System.String]::Format("{0}/app/rest/server/backup?addTimestamp={1}&includeConfigs={2}&includeDatabase={3}&includeBuildLogs={4}&includePersonalChanges={5}&fileName={6}",
$server,
$addTimestamp,
$includeConfigs,
$includeDatabase,
$includeBuildLogs,
$includePersonalChanges,
$fileName);
Write-Host "URL: " $TeamCityURL
Execute-HTTPPostCommand $TeamCityURL
}
$server = "http://localhost"
$addTimestamp = $true
$includeConfigs = $true
$includeDatabase = $true
$includeBuildLogs = $true
$includePersonalChanges = $true
$fileName = "TeamCity_Backup_"
Execute-TeamCityBackup $server $addTimestamp $includeConfigs $includeDatabase $includeBuildLogs $includePersonalChanges $fileName
Это завершается ошибкой с сообщением «Удаленный сервер возвратил ошибку: (500) Внутренняя ошибка сервера».
Из teamcity-server.log:
[2013-12-17 17:53:12,419] ERROR - jetbrains.buildServer.SERVER - Error java.lang.IllegalArgumentException: Argument for @NotNull parameter 'key' of jetbrains/buildServer/controllers/interceptors/auth/impl/WaffleBasedNTLMHttpAuthenticationStrategy.getValue must not be null while processing request: POST '/runtimeError.jsp?addTimestamp=True&includeConfigs=True&includeDatabase=True&includePersonalChanges=True&includeBuildLogs=True&fileName=TeamCity_Backup_', from client 0:0:0:0:0:0:0:1:61236, no auth/user
java.lang.IllegalArgumentException: Argument for @NotNull parameter 'key' of jetbrains/buildServer/controllers/interceptors/auth/impl/WaffleBasedNTLMHttpAuthenticationStrategy.getValue must not be null
at jetbrains.buildServer.controllers.interceptors.auth.impl.WaffleBasedNTLMHttpAuthenticationStrategy.getValue(WaffleBasedNTLMHttpAuthenticationStrategy.java)
at jetbrains.buildServer.controllers.interceptors.auth.impl.WaffleBasedNTLMHttpAuthenticationStrategy.doProcessAuthenticationRequest(WaffleBasedNTLMHttpAuthenticationStrategy.java:57)
Из teamcity-auth.log:
[2013-12-17 19:16:44,377] DEBUG [UA: null ; http-bio-80-exec-28] - Processing request with no authorization header: POST '/app/rest/server/backup?addTimestamp=True&includeConfigs=True&includeDatabase=True&includePersonalChanges=True&includeBuildLogs=True&fileName=TeamCity_Backup_', from client 0:0:0:0:0:0:0:1:55772, no auth/user
[2013-12-17 19:16:44,377] DEBUG [UA: null ; http-bio-80-exec-28] - No scheme was matched
[2013-12-17 19:16:44,377] DEBUG [UA: null ; http-bio-80-exec-28] - Processing unauthenticated request
[2013-12-17 19:16:44,377] DEBUG [UA: null ; http-bio-80-exec-28] - Responding with 401 HTTP status with message "Unauthorized", sending header in response: WWW-Authenticate: Basic realm="TeamCity", Basic realm="TeamCity", NTLM
[2013-12-17 19:16:44,377] DEBUG [UA: null ; http-bio-80-exec-26] - Processing request with authorization header: "NTLM": POST '/app/rest/server/backup?addTimestamp=True&includeConfigs=True&includeDatabase=True&includePersonalChanges=True&includeBuildLogs=True&fileName=TeamCity_Backup_', from client 0:0:0:0:0:0:0:1:55773, no auth/user, authorization data: "#########"
Я проверил учетные данные, под которыми запускается скрипт в веб-браузере (подсказка ntlm), и сайт TC загружается без проблем.
Есть идеи, что я сделал не так?