Forums

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

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

Jiwon Jeon
Contributor
April 14, 2023 edited

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 @Jiwon Jeon 

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

Jiwon Jeon
Contributor
April 16, 2023

It works! Thanks for your support :)

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

Like • 3 people like this
Bitwise DEVS
Contributor
February 27, 2024 edited

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!

Like • Christian Elowsky likes this

Suggest an answer

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

Atlassian Community Events