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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.