I need something like a teardown step
Asked by Dittmar_ Dirk:

Hello,

we're currently migrating from Bamboo. Bamboo had "final tasks" ... these tasks are fired even if the "normal" tasks were failing.

I'm looking for a replacement. I'm starting some docker containers on a remote maschine and have to stop them afterwards.

I'm thinking of something like "teardown steps" but couldn't find anythink like that.

Any Ideas?

Regards,

Dirk


Answers:
author: Dittmar_ Dirk
body: There is an suggestion for this: [Need for an "after-step"](https://jira.atlassian.com/browse/BCLOUD-18012)


author: Nicolas Grossi
body: [@Dittmar_ Dirk](/t5/user/viewprofilepage/user-id/5542640) Welcome! Are you referring to after steps?: <https://bitbucket.org/blog/after-scripts-now-available-for-bitbucket-pipelines>

Nicolas

comments: author: Dittmar_ Dirk
body: Hi, no... but kind of (I guess)

The "after-script" is run after the the "script" in the step...

I'm looking for a step after all the steps... I'm thinking of something like:

```
pipelines:
  custom:
    nightly-integration-tests:
      - stage:
          steps:
            - step:
                runs-on:
                  - self.hosted
                  - linux
                name: "start docker containers"
                image: atlassian/default-image:4
                script:
                  - |
                    ssh -o "StrictHostKeyChecking no" foo@bar 'bash -s' < start-postgres15-and-solr.sh
            - step:
                runs-on:
                  - self.hosted
                  - linux
                name: "run the integration tests"
                image: maven:3.9.5-eclipse-temurin-17-focal
                script:
                  - |
                    mvn ...
            - step: # or something like "after-steps"
                runs-on:
                  - self.hosted
                  - linux
                name: "shutdown docker containers"
                image: atlassian/default-image:4
                script:
                  - |
                    ssh -o "StrictHostKeyChecking no" foo@bar 'bash -s' < stop-all-docker-containers.sh
```


author: Saxea _Flowie_
body: Hi [@Dittmar_ Dirk](/t5/user/viewprofilepage/user-id/5542640)

Can you start the container as part of "run integration tests" and use \`after-script\` on that step to stop it?


author: Dittmar_ Dirk
body: Hi, no...

the "run the integration tests" is a step where I run a Maven3 build. The other steps use an image where I can run SSH "things". I could shove everything in one image but than I have to nurse that image myself... and where is the sense of the "steps" and stages then?

Maybe I can do something with conditions (or something like that)? ?


author: Saxea _Flowie_
body: Yeah, I see... You mean [start conditions](https://support.atlassian.com/bitbucket-cloud/docs/pipeline-start-conditions/)? ?


author: Dittmar_ Dirk
body: ... yes ... but that's only for conditions like "do this if files in some directory were changed" ... **and** the step is not executed because the pipeline stops at the step that has a non zero return code...


author: Saxea _Flowie_
body: hmm... yeah, the failure scenario would not work.

What you use 'after-script' with [trigger-pipe?](https://bitbucket.org/atlassian/trigger-pipeline/src/master/)

Set a \`after-script\` on every step after the setup and, check whether it has failed and trigger a 'clean up' pipeline for the intermediate steps, and always trigger on the last step?


author: Dittmar_ Dirk
body: hmmm ... no, but I see the idea...

The second step (see above) uses \`maven:3.9.5-eclipse-temurin-17-focal\` which does not have an ssh-client like the image in the last step (\`atlassian/default-image:4\`)

I guess I have to stuff everything in one image and use one step only... kinda anoying really... where can I file a feature request?


author: Saxea _Flowie_
body: If you define a separated 'clean up' pipeline you can use the 'atlassian/default-image:4'. So you would have 'nightly-integration-tests' pipeline which triggers 'clean up'.

Usually Atlassian support monitors the posts here and create a request if it doesn't already exists.


author: Dittmar_ Dirk
body: That's not a sulution ether ... I'm just testing with a one database but I have to build this for 5 other databases... like:

* for every supported databases do:
  * for every supported version do:
    1. start the database (on our own host via ssh)
    2. run all the integration tests (with maven)
    3. shutdown the database (via ssh)

so... I guess there is no easy way to do it ?


author: Theodora Boudale
body: Hi Dirk,

We have a feature request for an after-step here:

* <https://jira.atlassian.com/browse/BCLOUD-18012>

The request has been closed due to inactivity; no comments or votes for an extended period of time, so it didn't make it to the roadmap. However, you can still leave a comment with your use case to express your interest, as our product managers continue to monitor even closed requests.

The after-script is the only available option right now, and Saxea _Flowie_'s replies have covered what is possible.

Kind regards,  
Theodora


Tags: bitbucket-cloud

cloud

steps