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

Shiri Rave 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.

 

Thanks,

Shiri.

 

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?

 

Thanks.

---

 

 


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


pipelines:
default:
- step:
name: Build and Test
caches:
- node
- cypress
script:
# install dependencies
- echo '################# Printing vars to see what is available...###################'
- echo '"$FIRST_PARAM_FROM_WORKSPACE_OR_REPO"'
- export FIRST_PARAM_FROM_WORKSPACE_OR_REPO='"http"'
- echo '"$FIRST_PARAM_FROM_WORKSPACE_OR_REPO"'
- echo SECOND_PARAM_FROM_WORKSPACE_OR_REPO="$SECOND_PARAM_FROM_WORKSPACE_OR_REPO" >> .env
- echo FIRST_PARAM_FROM_WORKSPACE_OR_REPO="$FIRST_PARAM_FROM_WORKSPACE_OR_REPO" >> .env.local
- 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"
services:
- mongo
artifacts:
# 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
script:
- npm install eslint
- npx eslint .
caches:
- node
definitions:
services:
mongo:
image: mongo
caches:
npm: $HOME/.npm
cypress: $HOME/.cache/Cypress
======= Using the log, I see the following errors: ======
[494:0503/123609.061177:ERROR:bus.cc(392)] Failed to connect to the bus: Address does not contain a colon
[494:0503/123609.066478:ERROR:zygote_host_impl_linux.cc(263)] 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:
$FIRST_PARAM://<some_link>
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:
$SECOND_PARAM/<some_link>
-----------------------------------------------------
Thanks.

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"
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
TAGS
AUG Leaders

Atlassian Community Events