Windows Runners builds fail even on successful commands (0 exit code)
Platform Notice: Cloud Only - This article only applies to Atlassian products on the cloud platform.
Summary
When running builds on Bitbucket Pipelines Windows Runners and utilizing caching, it’s important to be aware of a potential scenario that can occur. Even if all commands from your build execute properly and return a 0 exit code, there may still be instances where the build could fail.
Environment
Bitbucket Pipelines Runners can be hosted on Windows operating systems. It is important to note that this specific issue arises exclusively when utilizing caching mechanisms.
Diagnosis
Check if the command is truly completing successfully. This can be done by checking the value of the $LastExitCode environment variable. By printing this variable to the after-script section of your build, you can easily verify the exit code of the command that was executed last. Here's an example of how to do this:
1
2
3
[...]
after-script:
- $LastExitCode
⚠️ If the command executed above yields a result of "0", it indicates that the command was successful, and you are experiencing the issue outlined on this page.
⚠️ Conversely, if the command returns a non-zero result, it signifies that the issue pertains to the command being executed, which intentionally failed the build due to an error. Therefore, the issue you are encountering is not associated with the problem described on this page.
Cause
This issue arises from improperly defined cache settings in your bitbucket-pipelines.yml file. When utilizing non-pre-defined caches, it is essential to configure the definitions section to specify the directory where the cache will be stored.
The absence of this section can lead to build failures, even if the commands within the build process execute correctly.
Solution
Check your bitbucket-pipelines.yml file, and examine the "definitions" section within it. It is essential to ensure that the definitions section accurately specifies the directory for the cache utilized in the affected build step, and that the directory in question exists.
An example of a valid caches definition is as follows:
1
2
3
definitions:
caches:
windows_bundler: vendor/bundle
If the issue persists after following the steps above, or if you are not using caches but are facing this issue, please reach out to Atlassian support, or the Atlassian community for further assistance.
Was this helpful?