DDiVita
DDiVita

Reputation: 4265

Can Bamboo interpret an HTTP 400 Bad request as a failure

We are using CURL to make an external API request to one of our applications. If that request comes back with something other than a 200 we want bamboo to fail the "build". Currently, it is passing. Also, the message in the response has the word "error" in it. My hope was that Bamboo was parsing the script outcome and reporting pass or fail based on the response. We could possibly leverage postman and have it run a test if bamboo is unable to interpret the actual request.

Here is the log:

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.

Upvotes: 2

Views: 1000

Answers (1)

Steffen Opel
Steffen Opel

Reputation: 64751

The Bamboo Script task determines its success or failure based on the shell's exit code, which equals the exist code of the last executed command (i.e. 0 for success, everything else for failure). However, curl does not consider any non 2xx HTTP responses to be an error by default, because even for 4xx and 5xx status codes curl itself worked correctly. You can tweak this via the --fail command line flag (from the curl man page):

-f, --fail

(HTTP) Fail silently (no output at all) on server errors. This is mostly done to better enable scripts etc to better deal with failed attempts. In normal cases when an HTTP server fails to deliver a document, it returns an HTML document stating so (which often also describes why and more). This flag will prevent curl from outputting that and return error 22.

This method is not fail-safe and there are occasions where non-successful response codes will slip through, especially when authentication is involved (response codes 401 and 407).

  • If the curl command is not the last one executed in the script, you could either save its exit code in a variable and return that, or if the shell is Bash, use e.g. set -e at the top of your script to make the shell "exit immediately if a command exits with a non-zero status". (more detailed explanation).

Upvotes: 3

Related Questions