Is it possible to retrieve artifacts from "failed' builds?
Asked by Sam Wainwright:

We're attempting to implement a basic smoke test suite using Pipelines + Cypress. Obviously, we'll want to have access to the video/screenshot artifacts of those runs *especially* if they fail, but it seems like the artifacts aren't available after a 'failed' step. Is what we're trying possible?


Answers:
author: Caroline R
body: Hi, [@Sam Wainwright](/t5/user/viewprofilepage/user-id/4631155)! Welcome to the community!

[Artifacts](https://support.atlassian.com/bitbucket-cloud/docs/use-artifacts-in-steps/) are not uploaded for the failed steps. Bitbucket pipelines are configured to stop at any non-zero exit code. That means that the pipeline execution is stopped when cypress fails the tests. Because artifacts are stored after the last step of the pipeline, you won't have any artifacts.

Bitbucket Pipelines achieves the default behavior of exiting on the first error by prepending your script with the "set -e" bash command. You can "undo" this at any point in your script using the command "set +e". If you want all the commands in your script to execute regardless of errors then put "set +e" at the top of your script. If you just want to ignore the error for one particular command then put "set +e" before that command and "set -e" after it.

Once the scripts are forcefully successful with the help of the method mentioned above, the artifacts upload part will be executed and they will be available for download later.

I hope this helps, but do let me know if you have any questions.

Kind regards,  
Caroline

comments: author: Sam Wainwright
body: Great, that did the trick. Thanks!


author: Caroline R
body: Hi, Sam! Thanks for your confirmation, I'm glad to know it worked!  
Kind regards,  
Caroline


author: Christian Sciberras
body: So the solution to getting failure results from a pipeline is to force the pipeline to look like it is successful??


author: Simon Schick
body: Is there any other option planned on integrating? This way, a build will be marked as successful even though it failed ... Can we get an option where we can enable the collection of artefacts on error?

comments: author: Caroline R
body: Hi, Simon.

Currently, Artifacts are not uploaded for failed steps. So, if you need that, we can create a feature request to implement it. We just need some additional details about your business case (the reason you need this feature) to raise this request.  
Kind regards,  
Caroline


author: Simon Schick
body: Thanks very much for your fast reply on this! Well, my business case is as described by the originator of the issue.

We use \`cypress\` to run our tests, which creates screen-recordings of tests which I want to access if the tests fail. Furthermore we use the same pipeline to automatically upload the build to our staging environment, which should not happen if the tests fail. Furthermore, a red test indicates that there's something wrong, so I'd like it red (to use bitbuckets notifications for failed tests) but still have access to the artifacts.

One possible solution could be to provide an option per registered artifact, where I can decide to have them 1. despite of the result - or - 2. only if failed or succeeded. The option "only on success" could then be the default option, as this is the behavior as it is today.

Does this sum it up?


author: Caroline R
body: Hi, Simon.

Thanks for sharing the additional details about your request. I have created the following feature request to add the option to retrieve artifacts from failed builds:

* <https://jira.atlassian.com/browse/BCLOUD-21636>

We suggest that you add your vote there (by selecting the **Vote for this issue** link) as the number of votes helps the development team and product managers better understand the demand for new features.

You are more than welcome to leave any feedback, and you can also add yourself as a watcher (by selecting the **Start watching this issue** link) if you'd like to get notified via email on updates.

Implementation of new features is done as per our policy [here](https://confluence.atlassian.com/support/implementation-of-new-features-policy-201294576.html) and any updates will be posted in the feature request.

Kind regards,   
Caroline


Tags: bitbucket-cloud

bitbucket-pipelines

cloud