Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Is it possible to run pipe conditionally in `after-script`?

전지원 April 14, 2023

Hi, I want to run pipe `slack-notify` conditionally after a step finished (in after-script statement).

 

Is there any syntax that run the pipe conditionally by checking BITBUCKET_EXIT_CODE (only when FAILED(1)) ?

 

Desired situation using pseudo-YAML:

```yaml

after-script:
  - envsubst < ".pipelines/failed_pipe_payload.json.template" > ".pipelines/slack_payload.json"
  - pipe: atlassian/slack-notify:2.0.0
     variables:
       WEBHOOK_URL: $SLACK_WEBHOOK_URL
       PAYLOAD_FILE: .pipelines/slack_payload.json
     condition:
        variables.BITBUCKET_EXIT_CODE: 1
```

1 answer

1 accepted

1 vote
Answer accepted
Oleksandr Kyrdan
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 14, 2023

Hi @전지원 

Thank you for your question!

You could try the next solution:

script:
- ...
after-script:
- if [[ BITBUCKET_EXIT_CODE -eq 0 ]]; then exit 0; else echo "Step failed"; fi
envsubst < ".pipelines/failed_pipe_payload.json.template" > ".pipelines/slack_payload.json"
- pipe: atlassian/slack-notify:2.0.0
...

 

Best regards,
Oleksandr Kyrdan

전지원 April 16, 2023

It works! Thanks for your support :)

I think it would be good if condition syntax is supported for pipe too!

Like # people like this
Bitwise DEVS February 27, 2024

Hi, I want to verify if `$` is really no longer needed in

`BITBUCKET_EXIT_CODE` since if I remember correctly it is always prepend to the variable name in order to use it?


Thanks!

Suggest an answer

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

Atlassian Community Events