Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Setting env vars in pipeline in configuration file

Deleted user Aug 12, 2021

I'm aware of the possibility to add pipeline environment variables and secret through the Bitbucket GUI. However I want to set my environmental variables in the `bitbucket-pipelines.yml` file.


Thus far the only way I found out to set these variables is by declaring the variables in the script of a step:

      - step:
- ->
- ->
- ->
./ && ./


With the configuration above is a script defined with 3 commands. Each command is trying to run an shell script `` and `` they both require the environmental variables `FOO` and `BAR` to be set. Unfortunately in the example above only the first command will run the shell scripts with all variables. Although the first command defines the `BAR` variable, it is lost in the second command where only the `FOO` variable is defined. In the third command `` runs fine but `` runs without any variables.


I wonder if it is possible to set variables for all or one specific pipeline and for a single step? Where will be kept in mind that variables (re-)defined on a lower level will override the more global variables. Preferably without the use of a custom pipeline.

2 answers

1 accepted

0 votes
Answer accepted
Mark C Atlassian Team Aug 23, 2021

Hi @[deleted],

Welcome to the community.

Would it be possible for you to try to use export while using environment variables?
Also, would you be able to try to use the script individually?

      - step:
            - chmod u+x
            - chmod u+x
            - export FOO=foo
            - export BAR=bar
            - ./
            - export FOO=foe
            - ./
            - export FOO=fou
            - export BAR=baz
            - ./ && ./

Let me know how it goes.

Mark C

Deleted user Aug 23, 2021

That works great, thank you very much my pipeline just got way better readable.

0 votes
Michael Moriarty Marketplace Partner Aug 19, 2021

Not sure if this is helpful but we use AWS variables within our bitbucket pipelines like so:



- echo "Building environment"

- cd ...

- pipe: atlassian/aws-elasticbeanstalk-deploy:0.2.3





Suggest an answer

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

Git push size limits are coming to Bitbucket Cloud starting April 4th, 2022

Beginning on April 4th, we will be implementing push limits. This means that your push cannot be completed if it is over 3.5 GB. If you do attempt to complete a push that is over 3.5 GB, it will fail...

2,170 views 2 9
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