4

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.

Ivy
  • 3,393
  • 11
  • 33
  • 46

2 Answers2

1

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"
Dan Bonachea
  • 2,408
  • 5
  • 16
  • 31
0

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
Doremi
  • 111
  • 1
  • 6
  • It does not work with or without `export`. The problem is variables set within the "script" are not passed to the "pipe". Only variables set within Bitbucket are available within the pipe. – Ivy Sep 28 '22 at 12:47
  • Are you sure ? Because I'm using something similare in my pipeline and it works. – Doremi Sep 29 '22 at 14:36