Pipes used within a Pipeline can accept parameters, the values can be environmental variables that are configured within Bitbucket (repo or deployment settings).
But if a variable is set within the Script section, that variable is not available when passing the value to the Pipe.
Is there any way to work around this?
script:
- export MY_MESSAGE = "Hello world"
- pipe: atlassian/slack-notify:0.2.1
variables:
WEBHOOK_URL: $WEBHOOK_URL
MESSAGE: $MY_MESSAGE
In that example, the value of $MY_MESSAGE is not passed to the MESSAGE parameter of atlassian/slack-notify because it would need to be set within Bitbucket itself.
The issue isn't the export but the spaces you're leaving between the variable name and its value:
Incorrect:
export MY_MESSAGE = "Hello world"
Correct:
MY_MESSAGE="Hello world"
This should work:
script:
- MY_MESSAGE="Hello world"
- pipe: atlassian/slack-notify:0.2.1
variables:
WEBHOOK_URL: ${WEBHOOK_URL}
MESSAGE: ${MY_MESSAGE}
Here a working example:
image: atlassian/default-image:2
definitions:
services:
docker:
memory: 3072
steps:
- step: &build
name: 'Build and push the docker image'
script:
# Local variables
- BITBUCKET_COMMIT_SHORT="${BITBUCKET_COMMIT::7}"
- MY_TAG="amazing"
# Build image
- docker build #......
# Push to repository
- pipe: atlassian/aws-ecr-push-image:1.6.2
variables:
IMAGE_NAME: ${CI_REGISTRY_IMAGE}
TAGS: '${BITBUCKET_COMMIT_SHORT} ${MY_TAG}' # -> ${MY_TAG} contains "amazing"
services:
- docker
caches:
- docker
pipelines:
branches:
testpipeline:
- step: *build
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With