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

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

How to use pipes across steps with just one variable change

I have a use case wherein I would like to use pipes in after scripts of my each step but with one variable change.

- step:
<<: *build-function
name: function1
script:
- *pre-build-steps
- cd abc/function1
- *build-steps
condition:
changesets:
includePaths:
- abc/function1/**
- abc/function3
after-script:
- echo $BITBUCKET_EXIT_CODE
- if [ $BITBUCKET_EXIT_CODE != 0 ]; then echo "Step failed";
- pipe: atlassian/email-notify:0.4.4
variables:
USERNAME: $AWS_SES_USERNAME
PASSWORD: $AWS_SES_PASSWORD
FROM: $FROM_EMAIL
TO: $TO_EMAIL
HOST: $HOST
PORT: $PORT
SUBJECT: 'Build Failed: function1'
ATTACHMENTS: '/opt/atlassian/pipelines/agent/build/abc/function1/coverage/index.html'
- fi;



- step:
<<: *build-function
name: function2
script:
- *pre-build-steps
- cd abc/function2
- *build-steps
condition:
changesets:
includePaths:
- abc/function2/**
- abc/function3
after-script:
- echo $BITBUCKET_EXIT_CODE
- if [ $BITBUCKET_EXIT_CODE != 0 ]; then echo "Step failed";
- pipe: atlassian/email-notify:0.4.4
variables:
USERNAME: $AWS_SES_USERNAME
PASSWORD: $AWS_SES_PASSWORD
FROM: $FROM_EMAIL
TO: $TO_EMAIL
HOST: $HOST
PORT: $PORT
SUBJECT: 'Build Failed: function2'
ATTACHMENTS: '/opt/atlassian/pipelines/agent/build/abc/function2/coverage/index.html'
- fi;

 

I have two questions:
1. Is there any way I can keep the pipe or the entire after-script as common (in definitions or something like that) and just change 1-2 variables depending on each step? So that I dont have to repeat 7-8 lines again and again. I have 20 steps and it will be excellent for me.

2. Is there a way, I can provide two variables in each step either through script (function name and function url) which can then be used in rest of the script, conditions and after-script. This will again help me keep the entire step in definition anchor (currently build-function is defined as anchor and has other common things such as cache, artifacts etc but couldnt make these common due to this small step specific change) and just use that variable.

 

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bitbucket Pipelines

Bitbucket Pipelines Runners is now in open beta

We are excited to announce the open beta program for self-hosted runners. Bitbucket Pipelines Runners is available to everyone. Please try it and let us know your feedback. If you have any issue...

3,650 views 63 19
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