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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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
4,461,899
Community Members
 
Community Events
176
Community Groups

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

Edited

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 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

Atlassian Community Events