Bamboo可以将HTTP 400 Bad请求解释为失败

时间:2018-03-01 14:40:25

标签: bamboo

我们正在使用CURL向我们的某个应用程序发出外部API请求。如果那个请求回来的东西不是200,那么我们希望竹子失败了#34; build"。目前,它正在过去。此外,响应中的消息包含单词" error"在里面。我希望Bamboo能够解析脚本结果并根据响应报告通过或失败。如果Bamboo无法解释实际请求,我们可以利用postman并让它运行测试。

这是日志:

simple  01-Mar-2018 08:43:29    Build Comcept.Net - Test Web API - Default Job #3 (COM-TWA-JOB1-3) started building on agent Default Agent
simple  01-Mar-2018 08:43:29    
simple  01-Mar-2018 08:43:29    Build working directory is D:\bamboo-home\xml-data\build-dir\COM-TWA-JOB1
simple  01-Mar-2018 08:43:29    Executing build Comcept.Net - Test Web API - Default Job #3 (COM-TWA-JOB1-3)
simple  01-Mar-2018 08:43:29    Running pre-build action: VCS Version Collector
simple  01-Mar-2018 08:43:29    Starting task 'Test Curl' of type 'com.atlassian.bamboo.plugins.scripttask:task.builder.script'
command 01-Mar-2018 08:43:29    Beginning to execute external process for build 'Comcept.Net - Test Web API - Default Job #3 (COM-TWA-JOB1-3)'\n ... running command line: \nD:\bamboo-home\temp\COM-TWA-JOB1-3-ScriptBuildTask-4890011895813643563.bat\n ... in: D:\bamboo-home\xml-data\build-dir\COM-TWA-JOB1\n ... using extra environment variables: \nbamboo_capability_system_builder_msbuild_MSBuild_v2_0__32bit_=C:\Windows\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe\nbamboo_capability_system_builder_msbuild_MSBuild_v14_0__64bit_=C:\Program Files (x86)\MSBuild\14.0\bin\amd64\MSBuild.exe\nbamboo_capability_system_builder_msbuild_MSBuild_2017=C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe\nbamboo_resultsUrl=http://britten.hq.comcept.net:8085/browse/COM-TWA-JOB1-3\nbamboo_capability_system_builder_msbuild_MSBuild_v4_0__32bit_=C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe\nbamboo_capability_system_builder_msbuild_MSBuild_v3_5__32bit_=C:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe\nbamboo_dependenciesDisabled=false\nbamboo_buildFailed=false\nbamboo_build_working_directory=D:\bamboo-home\xml-data\build-dir\COM-TWA-JOB1\nbamboo_buildKey=COM-TWA-JOB1\nbamboo_shortPlanName=Test Web API\nbamboo_capability_system_builder_msbuild_MSBuild_v3_5__64bit_=C:\Windows\Microsoft.NET\Framework64\v3.5\MSBuild.exe\nbamboo_agentWorkingDirectory=D:\bamboo-home\xml-data\build-dir\nbamboo_buildNumber=3\nbamboo_shortJobName=Default Job\nbamboo_buildResultsUrl=http://britten.hq.comcept.net:8085/browse/COM-TWA-JOB1-3\nbamboo_capability_system_builder_msbuild_MSBuild_v2_0__64bit_=C:\Windows\Microsoft.NET\Framework64\v2.0.50727\MSBuild.exe\nbamboo_capability_system_builder_node_Node_exe=C:\Program Files\nodejs\node.exe\nbamboo_capability_system_jdk_JDK_1_8_0_151__JRE_=C:\Program Files\Java\SE851\nbamboo_capability_system_jdk_JDK=C:\Program Files\Java\SE851\nbamboo_agentId=196609\nbamboo_planName=Comcept.Net - Test Web API\nbamboo_capability_system_builder_devenv_Visual_Studio_2010=C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\nbamboo_plan_storageTag=plan-3309569\nbamboo_shortPlanKey=TWA\nbamboo_ManualBuildTriggerReason_userName=ddivita\nbamboo_shortJobKey=JOB1\nbamboo_capability_system_builder_msbuild_MSBuild_v14_0__32bit_=C:\Program Files (x86)\MSBuild\14.0\bin\MSBuild.exe\nbamboo_capability_system_builder_msbuild_MSBuild_v4_0__64bit_=C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe\nbamboo_buildTimeStamp=2018-03-01T08:43:29.444-05:00\nbamboo_working_directory=D:\bamboo-home\xml-data\build-dir\COM-TWA-JOB1\nbamboo_planKey=COM-TWA\nbamboo_capability_system_jdk_JDK_1_8=C:\Program Files\Java\SE851\nbamboo_buildResultKey=COM-TWA-JOB1-3\nbamboo_buildPlanName=Comcept.Net - Test Web API - Default Job\n
build   01-Mar-2018 08:43:29    
build   01-Mar-2018 08:43:29    D:\bamboo-home\xml-data\build-dir\COM-TWA-JOB1>c:\curl\curl.exe -v https://api-qa.comcept.net/token 
error   01-Mar-2018 08:43:29      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
error   01-Mar-2018 08:43:29                                     Dload  Upload   Total   Spent    Left  Speed
error   01-Mar-2018 08:43:29    
error   01-Mar-2018 08:43:29      0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 192.168.0.220...
error   01-Mar-2018 08:43:29    * TCP_NODELAY set
error   01-Mar-2018 08:43:29    * Connected to api-qa.comcept.net (192.168.0.220) port 443 (#0)
error   01-Mar-2018 08:43:29    * ALPN, offering h2
error   01-Mar-2018 08:43:29    * ALPN, offering http/1.1
error   01-Mar-2018 08:43:29    * Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
error   01-Mar-2018 08:43:29    * successfully set certificate verify locations:
error   01-Mar-2018 08:43:29    *   CAfile: c:\curl\ca-bundle.crt
error   01-Mar-2018 08:43:29      CApath: none
error   01-Mar-2018 08:43:29    * TLSv1.2 (OUT), TLS header, Certificate Status (22):
error   01-Mar-2018 08:43:29    } [5 bytes data]
error   01-Mar-2018 08:43:29    * TLSv1.2 (OUT), TLS handshake, Client hello (1):
error   01-Mar-2018 08:43:29    } [512 bytes data]
error   01-Mar-2018 08:43:29    * TLSv1.0 (IN), TLS handshake, Server hello (2):
error   01-Mar-2018 08:43:29    { [81 bytes data]
error   01-Mar-2018 08:43:29    * TLSv1.0 (IN), TLS handshake, Certificate (11):
error   01-Mar-2018 08:43:29    { [3180 bytes data]
error   01-Mar-2018 08:43:29    * TLSv1.0 (IN), TLS handshake, Server key exchange (12):
error   01-Mar-2018 08:43:29    { [587 bytes data]
error   01-Mar-2018 08:43:29    * TLSv1.0 (IN), TLS handshake, Server finished (14):
error   01-Mar-2018 08:43:29    { [4 bytes data]
error   01-Mar-2018 08:43:29    * TLSv1.0 (OUT), TLS handshake, Client key exchange (16):
error   01-Mar-2018 08:43:29    } [70 bytes data]
error   01-Mar-2018 08:43:29    * TLSv1.0 (OUT), TLS change cipher, Client hello (1):
error   01-Mar-2018 08:43:29    } [1 bytes data]
error   01-Mar-2018 08:43:29    * TLSv1.0 (OUT), TLS handshake, Finished (20):
error   01-Mar-2018 08:43:29    } [16 bytes data]
error   01-Mar-2018 08:43:29    * TLSv1.0 (IN), TLS change cipher, Client hello (1):
error   01-Mar-2018 08:43:29    { [1 bytes data]
error   01-Mar-2018 08:43:29    * TLSv1.0 (IN), TLS handshake, Finished (20):
error   01-Mar-2018 08:43:29    { [16 bytes data]
error   01-Mar-2018 08:43:29    * SSL connection using TLSv1.0 / ECDHE-RSA-AES256-SHA
error   01-Mar-2018 08:43:29    * ALPN, server did not agree to a protocol
error   01-Mar-2018 08:43:29    * Server certificate:
error   01-Mar-2018 08:43:29    *  subject: CN=*.comcept.net
error   01-Mar-2018 08:43:29    *  start date: Feb 24 00:00:00 2018 GMT
error   01-Mar-2018 08:43:29    *  expire date: Jul 18 12:00:00 2020 GMT
error   01-Mar-2018 08:43:29    *  subjectAltName: host "api-qa.comcept.net" matched cert's "*.comcept.net"
error   01-Mar-2018 08:43:29    *  issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=RapidSSL RSA CA 2018
error   01-Mar-2018 08:43:29    *  SSL certificate verify ok.
error   01-Mar-2018 08:43:29    } [5 bytes data]
error   01-Mar-2018 08:43:29    > GET /token HTTP/1.1
error   01-Mar-2018 08:43:29    
error   01-Mar-2018 08:43:29    > Host: api-qa.comcept.net
error   01-Mar-2018 08:43:29    
error   01-Mar-2018 08:43:29    > User-Agent: curl/7.53.1
error   01-Mar-2018 08:43:29    
error   01-Mar-2018 08:43:29    > Accept: */*
error   01-Mar-2018 08:43:29    
error   01-Mar-2018 08:43:29    > 
error   01-Mar-2018 08:43:29    
error   01-Mar-2018 08:43:29    { [5 bytes data]
error   01-Mar-2018 08:43:29    < HTTP/1.1 400 Bad Request
error   01-Mar-2018 08:43:29    
error   01-Mar-2018 08:43:29    < Cache-Control: no-cache
error   01-Mar-2018 08:43:29    
error   01-Mar-2018 08:43:29    < Pragma: no-cache
error   01-Mar-2018 08:43:29    
error   01-Mar-2018 08:43:29    < Content-Length: 34
error   01-Mar-2018 08:43:29    
error   01-Mar-2018 08:43:29    < Content-Type: application/json;charset=UTF-8
error   01-Mar-2018 08:43:29    
error   01-Mar-2018 08:43:29    < Expires: -1
error   01-Mar-2018 08:43:29    
error   01-Mar-2018 08:43:29    < Server: Microsoft-IIS/7.5
error   01-Mar-2018 08:43:29    
error   01-Mar-2018 08:43:29    < X-Powered-By: ASP.NET
error   01-Mar-2018 08:43:29    
error   01-Mar-2018 08:43:29    < Date: Thu, 01 Mar 2018 13:44:21 GMT
error   01-Mar-2018 08:43:29    
error   01-Mar-2018 08:43:29    < 
error   01-Mar-2018 08:43:29    
error   01-Mar-2018 08:43:29    { [34 bytes data]
error   01-Mar-2018 08:43:29    
error   01-Mar-2018 08:43:29    100    34  100    34    0     0    241      0 --:--:-- --:--:-- --:--:--   241
error   01-Mar-2018 08:43:29    * Connection #0 to host api-qa.comcept.net left intact
build   01-Mar-2018 08:43:29    {"error":"unsupported_grant_type"}
simple  01-Mar-2018 08:43:29    Finished task 'Test Curl' with result: Success
simple  01-Mar-2018 08:43:29    Running post build plugin 'NCover Results Collector'
simple  01-Mar-2018 08:43:29    Running post build plugin 'Artifact Copier'
simple  01-Mar-2018 08:43:29    Running post build plugin 'npm Cache Cleanup'
simple  01-Mar-2018 08:43:29    Running post build plugin 'Clover Results Collector'
simple  01-Mar-2018 08:43:29    Running post build plugin 'Docker Container Cleanup'
simple  01-Mar-2018 08:43:29    Finalising the build...
simple  01-Mar-2018 08:43:29    Stopping timer.
simple  01-Mar-2018 08:43:29    Build COM-TWA-JOB1-3 completed.
simple  01-Mar-2018 08:43:29    Running on server: post build plugin 'NCover Results Collector'
simple  01-Mar-2018 08:43:29    Running on server: post build plugin 'Build Hanging Detection Configuration'
simple  01-Mar-2018 08:43:29    Running on server: post build plugin 'Clover Delta Calculator'
simple  01-Mar-2018 08:43:29    Running on server: post build plugin 'Maven Dependencies Postprocessor'
simple  01-Mar-2018 08:43:29    All post build plugins have finished
simple  01-Mar-2018 08:43:29    Generating build results summary...
simple  01-Mar-2018 08:43:29    Saving build results to disk...
simple  01-Mar-2018 08:43:29    Logging substituted variables...
simple  01-Mar-2018 08:43:29    Indexing build results...
simple  01-Mar-2018 08:43:29    Finished building COM-TWA-JOB1-3.

1 个答案:

答案 0 :(得分:2)

Bamboo Script task根据shell的退出代码确定其成功或失败,该退出代码等于 last 执行命令的现有代码(即0表示成功,其他一切表示失败)。但是,curl默认不会将任何非2xx HTTP响应视为错误,因为即使对于4xx和5xx状态代码,curl本身也能正常工作。您可以通过--fail命令行标志(来自curl man page)调整此内容:

  

-f, - fail

     

(HTTP)服务器错误无提示失败(根本没有输出)。这是   主要是为了更好地启用脚本等以更好地处理失败   尝试。在正常情况下,HTTP服务器无法提供   文档,它返回一个说明的HTML文档(通常也是如此)   描述了为什么以及更多)。此标志将阻止卷曲输出   那和返回错误22。

     

此方法不是故障安全的,并且有时会出现这种情况   不成功的响应代码将会漏掉,特别是在   涉及认证(响应代码401和407)。

  • 如果curl命令不是脚本中执行的最后一个命令,则可以将其退出代码保存在变量中并返回该命令,或者如果shell是Bash,则使用例如:脚本顶部的 set -e 使shell “如果命令以非零状态退出,则立即退出”。 (more detailed explanation)。