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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

If/Else condition in .yml file bitbucket Edited

Hi , 

 

Can anybody help me with a code snippet fot if else condition in email notiufy pipe. I am trying something like 

after-script:          
echo $BITBUCKET_EXIT_CODE         
if [ BITBUCKET_EXIT_CODE == 0 ]; then  echo "Step Successful"; fi; 
-  
pipeatlassian/email-notify:0.4.2              
variables:USERNAME'test@test.com'                
PASSWORD$PASSWORD                
FROM'test@test.com'                
TO$EMAILRECEIVERS               
HOST'smtp.gmail.com'               
BODY_PLAINEmail send from Bitbucket Pipeline <a href='https://bitbucket.org/${BITBUCKET_WORKSPACE}/${BITBUCKET_REPO_SLUG}/addon/pipelines/home#!/results/${BITBUCKET_BUILD_NUMBER}'>build#${BITBUCKET_BUILD_NUMBER}</a> . The deployment is successful.               
DEBUG'true'               
if [ BITBUCKET_EXIT_CODE != 0 ]; then  echo "Step failed"; fi;          
-  
pipeatlassian/email-notify:0.4.2              
variables               
USERNAME'test@test.com'                
PASSWORD$PASSWORD                
FROM'test@test.com'                
TO$EMAILRECEIVERS               
HOST'smtp.gmail.com'               
BODY_PLAINEmail send from Bitbucket Pipeline <a href='https://bitbucket.org/${BITBUCKET_WORKSPACE}/${BITBUCKET_REPO_SLUG}/addon/pipelines/home#!/results/${BITBUCKET_BUILD_NUMBER}'>build#${BITBUCKET_BUILD_NUMBER}</a> . The deployment failed.               
DEBUG'true'

Both the if condition is getting fired. 

2 answers

1 vote

Hi @NitinKhandelwal ,

The reason that both pipes are executed is because they are not part of the if conditions, but a separate command in the after-script. All commands in a script or after-script are executed sequentially (unless one fails and the build then fails).

That being said, I'm afraid that it is not possible to place a pipe within an if condition. The reason for this is that bash can't really recognize what a Pipe is, since it's something our team has implemented specifically for Pipelines, it's not something that bash would recognize.

We have a feature request for the ability to condition the execution of a pipe:

I would suggest to add your vote (by selecting the Vote for this issue link) as the number of votes helps the development team and product managers better understand the demand for new features. You are more than welcome to leave any feedback, and you can also add yourself as a watcher (by selecting the Start watching this issue link) if you'd like to get notified via email on updates.

Implementation of new features is done as per our policy here https://confluence.atlassian.com/support/implementation-of-new-features-policy-201294576.html and any updates will be posted in the feature request.

Please feel free to let me know if you have any questions.

Kind regards,
Theodora

1 vote

Hi @NitinKhandelwal  ,

Thank you for your question!

Let's simplify the code with an additional variable BUILD_STATUS:

after-script:
- echo $BITBUCKET_EXIT_CODE
- BUILD_STATUS="successful"
- if [[ $BITBUCKET_EXIT_CODE -ne 0 ]]; then BUILD_STATUS="failed" ; fi
- echo "Step ${BUILD_STATUS}"
- pipe: atlassian/email-notify:0.4.3
variables:
USERNAME: 'test@test.com'
PASSWORD: $PASSWORD
FROM: 'test@test.com'
TO: $EMAILRECEIVERS
HOST: 'smtp.gmail.com'
BODY_PLAIN: "Email send from Bitbucket Pipeline ... The deployment is ${BUILD_STATUS}."
DEBUG: 'true'

More recipes you could find by following the tag recipe  in the Atlassian Community.


Cheers,
Oleksandr Kyrdan

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

New Cloud Apps Roundup - Spring 2021

Atlassian's marketplace partners have had a very productive start to 2021! Since our last roundup, our developer community has added over 160 new cloud apps to the Atlassian Marketplace to help you...

84 views 1 12
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you