The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

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

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

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

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

 

 

DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events