使用 cURL 检索 TeamCity 中的当前构建状态
Using cURL to retrieve current build status in TeamCity
作为构建步骤,我尝试使用以下命令行代码来检索当前构建的构建状态:
curl –u "%system.teamcity.auth.userId%:%system.teamcity.auth.password%" \
"%teamcity.serverUrl%/httpAuth/app/rest/builds/id:%teamcity.build.id%/status"
当我在本地执行此操作时,它有效并且 returns 返回状态,例如。 FAILURE
但是,当我在 TeamCity Agent 上 运行 时,我得到以下反馈:
[15:11:21][Step 9/10] % Total % Received % Xferd Average Speed Time Time Time Current
[15:11:21][Step 9/10] Dload Upload Total Spent Left Speed
[15:11:21][Step 9/10] 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0curl: (6) Could not resolve host: –u
[15:11:21][Step 9/10] curl: (6) Could not resolve host: TeamCityBuildId=15124
[15:11:21][Step 9/10] 100 82 0 82 0 0 1536 0 --:--:-- --:--:-- --:--:-- 1536
[15:11:21][Step 9/10] "Authorization" header is not specified
[15:11:21][Step 9/10] To login manually go to "/login.html" page
[15:11:21][Step 9/10] Process exited with code 0
在我看来,它因为身份验证而倒塌了。但为什么会这样呢?我已经指定了访问凭据,为什么不能正确使用它们?
curl: (6) Could not resolve host: TeamCityBuildId=15124
表示某处参数不匹配,因为您的服务器未命名 TeamCityBuildId=15124
。
运行 curl.exe -u "user:password" "http://thisdomaindoesnotexist/httpAuth/app/rest/b
uilds/id:1234/status"
给我 curl: (6) Couldn't resolve host 'thisdomaindoesnotexist'
你的 curl 命令(具有正确的参数)在 TeamCity 中对我有效:
[21:11:57]Step 1/1: Test (Command Line)
[21:11:57][Step 1/1] Starting: C:\curl-7.45.0\bin\curl.exe -u username:password http://secret.cloudapp.net/httpAuth/app/rest/builds/id:1234/status
[21:11:57][Step 1/1] in directory: C:\TeamCity\buildAgent\work6bb6a03438b498
[21:11:57][Step 1/1] % Total % Received % Xferd Average Speed Time Time Time Current
[21:11:57][Step 1/1] Dload Upload Total Spent Left Speed
[21:11:57][Step 1/1] 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
[21:11:57][Step 1/1] 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
[21:11:57][Step 1/1] 100 7 0 7 0 0 64 0 --:--:-- --:--:-- --:--:-- 64
[21:11:57][Step 1/1] SUCCESS
[21:11:57][Step 1/1] Process exited with code 0
此键有效:
--user login:password
而不是:
-u
我 Windows 10
上 curl 7.45
。
作为构建步骤,我尝试使用以下命令行代码来检索当前构建的构建状态:
curl –u "%system.teamcity.auth.userId%:%system.teamcity.auth.password%" \
"%teamcity.serverUrl%/httpAuth/app/rest/builds/id:%teamcity.build.id%/status"
当我在本地执行此操作时,它有效并且 returns 返回状态,例如。 FAILURE
但是,当我在 TeamCity Agent 上 运行 时,我得到以下反馈:
[15:11:21][Step 9/10] % Total % Received % Xferd Average Speed Time Time Time Current
[15:11:21][Step 9/10] Dload Upload Total Spent Left Speed
[15:11:21][Step 9/10] 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0curl: (6) Could not resolve host: –u
[15:11:21][Step 9/10] curl: (6) Could not resolve host: TeamCityBuildId=15124
[15:11:21][Step 9/10] 100 82 0 82 0 0 1536 0 --:--:-- --:--:-- --:--:-- 1536
[15:11:21][Step 9/10] "Authorization" header is not specified
[15:11:21][Step 9/10] To login manually go to "/login.html" page
[15:11:21][Step 9/10] Process exited with code 0
在我看来,它因为身份验证而倒塌了。但为什么会这样呢?我已经指定了访问凭据,为什么不能正确使用它们?
curl: (6) Could not resolve host: TeamCityBuildId=15124
表示某处参数不匹配,因为您的服务器未命名 TeamCityBuildId=15124
。
运行 curl.exe -u "user:password" "http://thisdomaindoesnotexist/httpAuth/app/rest/b
uilds/id:1234/status"
给我 curl: (6) Couldn't resolve host 'thisdomaindoesnotexist'
你的 curl 命令(具有正确的参数)在 TeamCity 中对我有效:
[21:11:57]Step 1/1: Test (Command Line)
[21:11:57][Step 1/1] Starting: C:\curl-7.45.0\bin\curl.exe -u username:password http://secret.cloudapp.net/httpAuth/app/rest/builds/id:1234/status
[21:11:57][Step 1/1] in directory: C:\TeamCity\buildAgent\work6bb6a03438b498
[21:11:57][Step 1/1] % Total % Received % Xferd Average Speed Time Time Time Current
[21:11:57][Step 1/1] Dload Upload Total Spent Left Speed
[21:11:57][Step 1/1] 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
[21:11:57][Step 1/1] 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
[21:11:57][Step 1/1] 100 7 0 7 0 0 64 0 --:--:-- --:--:-- --:--:-- 64
[21:11:57][Step 1/1] SUCCESS
[21:11:57][Step 1/1] Process exited with code 0
此键有效:
--user login:password
而不是:
-u
我 Windows 10
上 curl 7.45
。