使用cURL检索TeamCity中的当前构建状态

时间:2016-09-16 14:19:24

标签: curl teamcity

作为构建步骤,我尝试使用以下命令行代码来检索当前构建的构建状态:

curl –u "%system.teamcity.auth.userId%:%system.teamcity.auth.password%" \
        "%teamcity.serverUrl%/httpAuth/app/rest/builds/id:%teamcity.build.id%/status"

当我在本地执行此操作时,它会起作用并返回状态,例如。 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

在我看来,由于身份验证,它已经失败了。但为什么会这样呢?我已经指定了访问凭据,为什么它没有正确使用它们?

2 个答案:

答案 0 :(得分:1)

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\work\316bb6a03438b498
[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

答案 1 :(得分:0)

它起到了这个作用:

--user login:password

而不是:

-u

curl 7.45 Windows 10对我来说。