making bitbucekt pipelines fail on atlassian/ssh-run:0.2.2 pipe errors
Asked by Gangadhar Mamillapalli:

When we are using  
atlassian/ssh-run:0.2.2. pipe in our bitbucket pipelines to run some commands like  
==\> tsc (type script compilaton in Node Project), if there are some compilation issues, pipielines are still getting passed.  
How to make it fail if there are some compilation issues or GIT issues.


Answers:
author: lissyaka
body: [@Gangadhar Mamillapalli](/t5/user/viewprofilepage/user-id/3036792), [@Patrik S](/t5/user/viewprofilepage/user-id/4603309) hi.  
Our team can confirm this pipe have an issue according to: [bash over ssh problem](https://unix.stackexchange.com/questions/489737/bash-script-executed-over-ssh-returns-incorrect-exit-code-0)

So even if your script fails with exit 1, pipe still be successful.

We will release a new version of pipe, when we will fix this.

Cheers.

comments: author: lissyaka
body: Update.  
So after some tests executed i cannot confirm the bug exists.  
If you provide this in your bash script:

```
cat non_existent_file
```

then the pipe will fail as expected: \`Execution failed.\`  
But if you provide this in your bash script:

```
cat non_existent_file;echo $??
```

then the pipe will end with success status: \`Execution finished.\` Despite the fact the result of \`**echo $?** \` was **1,** the status of the **last** command is**0**

```
cat non_existent_file;echo $? 
> cat: non_existent_file: No such file or directory
> 1
echo $?
> 0
```

What can help you is manual call of exit 1 if needed if you have multiple commands in your script, something like this  

```
cat non_existent_file;

if [ $? -ne 0 ]; then
  exit 1
  fi

echo $?
```

then:

```
bash -s < test.sh 
> cat: non_existent_file: No such file or directory
echo $?
> 1
```

Problem described in my previous response relates to bash command, not to bash script and was already solved.  

We will update the pipe with some additional tests to provide more coverage, but no changes to logic.  

<br />

Cheers


author: Patrik S
body: Hello [@Gangadhar Mamillapalli](/t5/user/viewprofilepage/user-id/3036792) ,

Thank you for reaching out to Atlassian Community!

In theory, as long as the commands/scripts you are running in the ssh pipe are returning a non-zero exit code when they fail, the pipe step should fail as well. An exit code is a number returned by the executable to show whether it was successful or not. The standard for Linux/Unix systems is to return 0 for success and any number from 1 to 255 for anything else.

What might be happening is that, although the command you are executing is failing, it's still returning a 0 (zero) exit code, which for the pipe means successful execution.

To confirm that you can execute locally the same command/script you are doing in the pipe, and print the value of **$?** right after it, as **$?**will contain the exit code of the last executed command. The test would be like the following :

```
bash <command/script you are runnin in the pipe>; echo $??
```

If the command/script fails and still returns an exit code 0, this is the reason why you are seeing the pipe as successful in this case.

Hope that helps. Let me know if you have any questions.

Thank you, [@Gangadhar Mamillapalli](/t5/user/viewprofilepage/user-id/3036792) .

Kind regards,

Patrik S

comments: author: Gangadhar Mamillapalli
body: Thank you [@Patrik S](/t5/user/viewprofilepage/user-id/4603309) for the hint, its returning non zero value only but some how its not breaking the pipelines, will check more on this and come back.

thanks


Tags: bitbucket-cloud

cloud

ssh