It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Can custom pipes read repository variables?

Hi,

I have written a custom pipe that accepts variables. If I explicitly pass the variables to the pipe in my bitbucket-pipelines.yml file, it works as expected. However, from some of the documentation I have read online (specifically this one - see Default Variables section), it suggests that it should be able to read the variables from the context.

There is a good chance that I have misunderstood what this means. I am assuming that any environment variable that I have defined at the account, repository or deployment level would get passed into the pipe when I define a variable in the pipe.yml and default it to the environment variable - as shown on that linked article. However, if I do not explicitly pass the variable into the pipe then it doesn't work.

Is there a step I have missed, or something I have not enabled etc to get this to work? Or I have misunderstood the feature and it is not possible. Any help would be greatly appreciated.

 

Here is what I have put together.

I have created the repository variable.

 

Screenshot 2020-03-26 at 13.03.02.png

Custom Pipe:

Dockerfile

FROM alpine:3.11

RUN apk --update --no-cache add \
bash

RUN wget -P / https://bitbucket.org/bitbucketpipelines/bitbucket-pipes-toolkit-bash/raw/0.4.0/common.sh

COPY ./pipe.sh ./pipe.yml /

ENTRYPOINT ["/pipe.sh"]

pipe.sh

#!/usr/bin/env bash
#
# Echos the test variable
#
# Required globals:
# TEST_VARIABLE
#

source "$(dirname "$0")/common.sh"

# mandatory parameters
TEST_VARIABLE=${TEST_VARIABLE:?'TEST_VARIABLE variable is missing.'}

echo ${TEST_VARIABLE}

success 'Test variable has been passed through'

pipe.yml

name: CustomPipe
variables:
- name: TEST_VARIABLE
  default: '${TEST_VARIABLE}'

 

Pipeline:

bitbucket-pipelines.yml - This version works

image:
name: atlassian/default-image:2
pipelines:
branches:
master:
- step:
name: Run pipe
script:
- pipe: <url for pipe>
variables:
TEST_VARIABLE: ${TEST_VARIABLE}
 

This succeeds echoing the value in the variable and displays the success message:

Testing

Test variable has been passed through

 

bitbucket-pipelines.yml - My assumption is that this version should work too, but it fails

image:
name: atlassian/default-image:2
pipelines:
branches:
master:
- step:
name: Run pipe
script:
- pipe: <url for pipe>

 I get this failure message as per the pipe.sh:

/pipe.sh: line 12: TEST_VARIABLE: TEST_VARIABLE variable is missing.

1 answer

Hi,

   I am also facing the same issue as mentioned in below:

https://community.atlassian.com/t5/Bitbucket-Pipelines-questions/rpc-error-when-testing-bitbucket-pipeline-with-opsgenie/qaq-p/1330454

 

I also tried to pass the variables through the repository variables but the values are not getting passed to the docker container. Not sure what is the right way to achieve this...

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bitbucket Pipelines

What We Learned When We Researched Open Source Vulnerabilities in 7 Popular Coding Languages

...hey are a part of us, shaping how we interact with the world around us. The same holds true for programming languages when we think about how different kinds of vulnerabilities raise their heads in t...

608 views 0 1
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you