Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Saving a custom cache even when the build step fails

rpate
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 14, 2026

We use the tool PHPStan to perform static analysis on our codebase. We've defined a custom cache as follows and are using it in a step in our pipeline.

definitions:
caches:
phpstan:
key:
files: # the files you want pipelines to check for changes when deciding whether to use the cache, or download fresh dependencies.
- composer.lock
path: tmp # same as in phpstan.neon

pipelines:
default:
- step:
name: Static Analysis
script:
- composer install
- vendor/bin/phpstan
caches:
- composer
- phpstan

 We can see that when the step succeeds (there are no static analysis warnings) the cache step proceeds and saves the cache if necessary.

The desired behavior is to save and upload the phpstan cache even if the pipeline step fails. If there are only errors in one file, then the entire cache apart from that one file is valid and can be reused in a later pipeline run once the errors in the single file have been resolved.

We can "trick" the pipeline by changing `vendor/bin/phpstan` to `vendor/bin/phpstan || exit 0` which allows the cache to be saved, but obviously masks any errors that occurred during the step.

Both Github and Gitlab allow caching steps to run even if the step/action fails PHPStan CI Documentation 

Is there analogous behavior in Bitbucket?

1 answer

0 votes
Mark C
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 17, 2026

Hi @rpate

Welcome to the community.

Unfortunately, Bitbucket Cloud Pipelines don't cache when a build is failed. It will only cache when the build is succeeded.

If you'd like to cache from anywhere of build, you might be interested in using Packages.

Regards,
Mark C

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events