The after-script commands are not running at all on some pipelines
Asked by Konstantinos:

The after-script section in the following custom pipeline is never triggered:

```
pipelines:
  custom:
    test-job:
      - step:
          name: Run Postman
          image: alpine:3.15
          script:
            - apk add npm bash
            - npm install -g newman
            - echo "This runs"
          after-script:
            - echo "This doesn't run"
```

Although the following works:

```
pipelines:
  custom:
    test-job:
      - step:
          name: Run Postman
          image: alpine:3.15
          script:
            - echo "This runs"
          after-script:
            - echo "This also runs"?
```

This seems like a pipeline bug to me. Any ideas what might be causing this?


Answers:
author: Syahrul
body: Hey [@Konstantinos](/t5/user/viewprofilepage/user-id/5022660)

Welcome to the community!

I tested and verified that this issue is only reproducible on the **alpine** image and other docker image works fine.

Further investigation, I found out that this was caused by the command

```
add npm bash??
```

The root cause it's a little complex, but the simplified version is before we start the build, we will try to check if \`/bin/bash\` existed or not. If yes, we add a special redirection command in "\~/.bashrc" to make the output redirect correctly.

However, because alpine does not have a \`/bin/bash\` build-in, we don't put that file in the image, and when the user installs bash in the build script, our after build script would find "/bin/bash" and execute after build script in bash context. It would miss the log because it doesn't have \`\~/.bashrc\` in place, so it doesn't redirect properly.

There are two suggestion to fix it, which is:

* Don't install bash
* Use an image that already has bash installed.

I hope this helps.

Cheers,  
Syahrul

comments: author: Konstantinos
body: Hi [@Syahrul](/t5/user/viewprofilepage/user-id/744536) ,  

Thanks a lot for the explanation. Is there a way to submit a bug report for this issue?


author: Syahrul
body: Hi [@Konstantinos](/t5/user/viewprofilepage/user-id/5022660)

I don't classify this as a bug because it's expected behavior, and this is more towards a feature since the issue happens because the **alpine** image doesn't include \`/bin/bash\` in their image.

I would suggest you raise the feature with the alpine team [here](https://github.com/alpinelinux/docker-alpine/issues) .

Cheers,  
Syahrul


author: Konstantinos
body: [@Syahrul](/t5/user/viewprofilepage/user-id/744536)I still believe this is a bug due to the following reasons:  

- The shell used on the image shouldn't interact in any way with the CI. The same jobs work fine on all other major CI solutions (github, gitlab, circleci). Bitbucket is the odd one out here.

- If this is expected behavior are there any docs? The job fails silently without an error message and the user isn't able to debug on their own.


author: Syahrul
body: Hi [@Konstantinos](/t5/user/viewprofilepage/user-id/5022660)

Apologize for the confusion. It makes more sense to have an error message on the build log.

I did check with our devs team and found out that we already have an existing bug report on this at:

* [Adding bash to the image skips after-script output.](https://jira.atlassian.com/browse/BCLOUD-22067)

I highly suggest you **Vote** and click **This affects my team** so that you'll receive an update whenever we have any in the future.

Cheers,  
Syahrul


Tags: bitbucket-cloud

cloud