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

Bitbucket pipeline problem overriding variable when using anchors and pipes

Պարապ Սարապ
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 11, 2023

Hello,
I have generic step to send slack message. It is using BB in-house pipe.

However, I want to reuse this step in later steps with overriding env varibales.
How I can do that ?

( we deliberately want to use variables to be present in bitbucket pipeline file and not relay on UI option bitbucket provide, since it is hard to have "change control" over there )

 - step: &notify_step
script: &slack_pipe
- pipe: atlassian/slack-notify:2.0.0
variables:
WEBHOOK_URL: $WEBHOOK_URL
PRETEXT: "*Hello*"
MESSAGE: "MYVAR is $MYVAR"


- step: &notify_staging
<<: *notify_step
name: Notify Staging
script:
- export MYVAR=xxx
- *slack_pipe


Code above doesn't work:

This section should be a string or a map (it is currently defined as a list).

 

 

1 answer

1 vote
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 12, 2023

Hi @Պարապ Սարապ and welcome to the community!

 If you use overrides with <<: *notify_step, you cannot add a script with additional commands in the step.

What you can do instead is add a definition for the pipe and then use this definition in different steps. An example is the following:

image: atlassian/default-image:4

definitions:
  pipes:
    - pipe: &slack_pipe
pipe: atlassian/slack-notify:2.0.0
variables:
    WEBHOOK_URL: $WEBHOOK_URL
    PRETEXT: "*Hello*"
    MESSAGE: "MYVAR is $MYVAR"

pipelines:
  default:
    - step:
        name: Notify staging
        script:
          - export MYVAR="XXX"
          - *slack_pipe
    - step:
        name: Notify production
        script:
          - export MYVAR="YYY"
          - *slack_pipe

Does this work for you? 

Kind regards,
Theodora

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events