Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,368,660
Community Members
 
Community Events
168
Community Groups

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.

 

1 answer

0 votes
Mark C Atlassian Team Sep 17, 2021

Hi @nagarro_bhavya

Thank you for reaching out to the community.

AFAIK, I'm afraid it is not possible to use dynamic variables in Pipelines YAML at the moment.
You will have to define your variables before running your builds.
We do have an existing feature request for it that can be located through this link. - https://jira.atlassian.com/browse/BCLOUD-15849
You can upvote and watch it for now so that you'll be notified of any updates from our team when the feature becomes available on Bitbucket Cloud.

For the after-script to be used as YAML anchors, it's not also possible at the moment as you can only use step as an anchor.

You can, however, use custom variables in a custom step.
However, I'm not sure if this is applicable to you.

Regards,
Mark C

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events