Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Problem reading env variables in bitbucket pipeline - with cypress and npm

Shiri Rave
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 3, 2022

Hi bitbucket team & community,

I am trying to build a pipeline for automating cypress tests.

Currently I am getting no indication what so ever that the defined env variables (primarily defined in the repo, workspace and test deploy environment) has been read. when printing the vars using 'echo', i get their names and not their values.

Currently I am get errors indicating that the env params has not been read.  

I am also new to yml and would appreciate a clue on how to change the above file using variables etc.

Below is a shortened version for my bitbucket-pipelines.yml file and some of the errors I'm getting.





p.s: Update: 


I have found out that the params are not read when using repo 'secured' button, and read otherwise. why is that? how can I use then when secured?






image: cypress/browsers:node14.17.0-chrome88-ff89

- step:
name: Build and Test
- node
- cypress
# install dependencies
- echo '################# Printing vars to see what is available...###################'
- cat .env
# install dependencies
- npm install
- npm ci
- npx browserslist@latest --update-db
# start the server in the background
- npm run start:ci &
# run Cypress tests in Firefox
# - npx cypress run --browser chrome
- npx cypress run --spec "cypress/integration/my_test_file.spec.js"
- mongo
# store any generates images and videos as artifacts
- cypress/screenshots/**
- cypress/videos/**
# install dependencies
- npm ci
# start the server in the background
- npm run start:ci &
# run Cypress tests
- npm run e2e
- step:
name: Code linting
- npm install eslint
- npx eslint .
- node
image: mongo
npm: $HOME/.npm
cypress: $HOME/.cache/Cypress
======= Using the log, I see the following errors: ======
[494:0503/] Failed to connect to the bus: Address does not contain a colon
[494:0503/] Failed to adjust OOM score of renderer with pid 781: Permission denied (13)
Browserslist: caniuse-lite is outdated. Please run:
npx browserslist@latest --update-db
Why you should do it regularly:
share anyone
1) "before all" ..
0 passing (843ms)
1 failing
"before all" hook for "(First initial method before testing)":
CypressError: `cy.request()` failed trying to load:

1 answer

1 vote
Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 10, 2022

Hello @Shiri Rave ,

Welcome to Atlassian Community!

Looking at your yml file, I think you are using the wrong syntax to reference the variables, because you are surrounding the variables with single quotes, and this might be the reason why you are not seeing them printed. When using single quotes around the variable name, it will print the name and not the actual value of the variable.

The below syntax examples should work when referring an environment variable in pipelines :

echo "$IMAGE_NAME"
echo "${IMAGE_NAME}"

Also, if you are trying to echo a variable that was marked as Secure, it's expected that just the variable name is shown in the logs. This happens because secure variables are meant to be used for sensitive information, such as passwords or access tokens, and thus pipelines masks secure variables so they are not disclosed to your team members viewing build logs. If a value matching a secured variable appears in the logs, Pipelines will replace it with $VARIABLE_NAME.

What you can do to test your script is to create the variable without Secure flag, give it a test value, and run your build to see if it's correctly printed in the echo command. Once confirmed, you can recreate the variable using the same name, but now with Secure flag and update it's value to the correct one.

For more details about secure variables please refer to the documentation below :

Hope that helps! Let me know if you have any question.

Thank you @Shiri Rave !

Kind regards,

Patrik S

Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events