Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Using anchors with pipes

Troy Elliott
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!
April 11, 2019

What is the correct way to override values for a bitbucket pipeline anchor when inside a pipe?  The use case is that I want slack notifications to be sent to the same channel with only the message variable different depending on where it is called.

Currently I have the following definition

definitions:
steps:
- step: &slack-alert
name: Slack alert
script:
- pipe: atlassian/slack-notify:0.2.0
variables:
WEBHOOK_URL: "https://hooks.slack.com/services/super/secret"
MESSAGE: Generic slack message from bitbucket

 

and the relevant step that calls it

 - step:
<<: *slack-alert
name: "#deploystatus qa"
script:
- pipe: atlassian/slack-notify:0.2.0
variables:
MESSAGE: "Custom text for the qa (staging) environment\n<https://qa.google.com/|qa.google.com>"

 

The issue is that since the MESSAGE is not at the top-level tab (whereas name is), I need to specify additional info that, in theory, should be inherited from the definition.

1 answer

1 accepted

4 votes
Answer accepted
Tom Bradshaw
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 14, 2019

Hi @Troy Elliott ,

The problem seems to be that yaml inheritance is quite strict; if you want to overwrite one sub-field, like message, you'll have to overwrite all of them.

To avoid having to redefine every pipe variable again you can use more anchors and references as seen in the example below.

definitions:
steps:
- step: &slack-alert
name: Slack alert
script:
- pipe: atlassian/slack-notify:0.2.0
#Next line is changed
variables: &pipe-variables
WEBHOOK_URL: "https://hooks.slack.com/services/super/secret"
MESSAGE: Generic slack message from bitbucket


pipelines:
- step:
<<: *slack-alert
name: "#deploystatus qa"
script:
- pipe: atlassian/slack-notify:0.2.0
variables:
#Next line has been added
<<: *pipe-variables
MESSAGE: "Custom text for the qa (staging) environment\n<https://qa.google.com/|qa.google.com>"

 Cheers,

Tom.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events