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.