How to know exit code of last failed step?

Ajay August 6, 2024

I use windows based runner and sometimes my build system fails with exit code 2 or 3 that's not entirely a failure but warnings.  

1. I would like to see them in bitbucket pipeline logs which I tried with after-script echo but doesn't work

2. Is there a way to tell pipeline fail a step only for exit code 1 and don't fail for other codes?

 

Thanks,
Ajay

1 answer

0 votes
Syahrul
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 7, 2024

G'day, @Ajay 

Have you tried adding the echo command to show the exit code at the end of your script, for example:

- Running a command; echo "Exit code: $?"

Regards,
syahrul

Ajay August 22, 2024

Pipelien fails at the line and doesn't proceed further.  I would not be able run Exit Code $? after the failure of the step.

Syahrul
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 22, 2024

Hi @Ajay 

If that's the case, maybe run your steps in a bash script for example:

#!/bin/bash

# Run your command
your_command_here

# Capture the exit code
EXIT_CODE=$?

# Check the exit code and decide whether to exit with an error
if [ $EXIT_CODE -eq 1 ]; then
echo "Command failed with exit code 1, failing the step."
exit 1
else
echo "Command completed with exit code $EXIT_CODE, but not failing the step."
exit 0
fi

This will check for exit code, and if the exit code is 1, it will failed the steps, otherwise it'll return complete steps.

Regards,
Syahrul

 

 

Suggest an answer

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

Atlassian Community Events