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:
pipelines:
default:
steps:
- step:
script:
- ->
FOO=foo
BAR=bar
./app1.sh
- ->
FOO=foe
./app2.sh
- ->
FOO=fou
BAR=baz
./app1.sh && ./app2.sh
With the configuration above is a script defined with 3 commands. Each command is trying to run an shell script `app1.sh` and `app2.sh` 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 `app1.sh` runs fine but `app2.sh` 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.
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?
pipelines:
default:
- step:
script:
- chmod u+x app1.sh
- chmod u+x app2.sh
- export FOO=foo
- export BAR=bar
- ./app1.sh
- export FOO=foe
- ./app2.sh
- export FOO=fou
- export BAR=baz
- ./app1.sh && ./app2.sh
Let me know how it goes.
Regards,
Mark C
That works great, thank you very much my pipeline just got way better readable.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Not sure if this is helpful but we use AWS variables within our bitbucket pipelines like so:
script:
- echo "Building environment"
- cd ...
- pipe: atlassian/aws-elasticbeanstalk-deploy:0.2.3
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.