Forums

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

BITBUCKET_EXIT_CODE not present in windows runner

João Guilherme Silva Machado
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!
September 19, 2025

When Windows Runner fails, it does not have the BITBUCKET_EXIT_CODE variable or any other to use in the after script step. The variable dont have a value, so it is always running the after script step.


- step: &test_after-script_windows

name: echo test windows

runs-on:

- self.hosted

- windows

script:

- echo teste windows

- echo $env:PACKAGE_VERSION

- echo $env:AWS_S3_BUCKET

- awscli run dotnet

after-script:

- echo $LastExitCode

- echo $BITBUCKET_EXIT_CODE

- |

if ($BITBUCKET_EXIT_CODE -ne 1) {

echo "Windows build step failed, running rollback"

} else {

echo "Windows build step succeeded"

}

1 answer

1 accepted

2 votes
Answer accepted
João Guilherme Silva Machado
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!
September 19, 2025

I was missing the $env when calling the value

$env:BITBUCKET_EXIT_CODE
Derick Downey September 23, 2025

That one tripped me up too when getting started. There is an article about it now, but I didn't see it in the original references: https://support.atlassian.com/bitbucket-cloud/kb/how-to-access-environment-variables-in-windows-runners-on-bitbucket-cloud-pipelines/

Here's another thing that tripped me up for a while. In order for the runner computer to connect to the Bitbucket cloud, you need to run that `start.ps1` script. This means that if your runner reboots, you need to re-run that script before it will start again. I ended up getting mine mostly working by using Windows Task Scheduler to run the `start.ps1` script, but it still is finicky sometimes. I found this article recently and have yet to do it this way, but this seems promising: https://support.atlassian.com/bitbucket-cloud/kb/bitbucket-cloud-pipelines-set-up-runners-for-windows-as-a-windows-service/

Suggest an answer

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

Atlassian Community Events