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"
}
I was missing the $env when calling the value
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/
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.