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

Passed variables to npm script are empty

senad87 November 12, 2021
I have the following in the bitbucket-pipeline.yml:

script
:
- npm install
- API_URL=$API_URL npm run build

and unsecured deployment variable API_URL that has value https://example.com

console.log(process.env.API_URL)  show nothing in the pipeline log when build is started.

When using hardcoded url everything works as expected:

script
:
- npm install
- API_URL=https://example.com npm run build

Not sure what am I doing wrong?

Any help is much appreciated.

2 answers

1 accepted

0 votes
Answer accepted
senad87 January 19, 2022

Thank you @Syahrul

It was a missunderstaning on my part. I was expecting that deployment variables are accessible acros all steps.

I solved it by creating repository level variables, since those can be used in all steps.

Thanks again, cheers!
0 votes
Syahrul
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 9, 2022

Hi @senad87 

Welcome to the community!

Could you try to add echo on the variable before the steps that you use to call it to verify that pipeline is correctly showing the variable as the following example:

        script:
             - echo "$API_URL"

 This should create an echo output of the variable in the pipeline build where you can use to verify if the variable is correctly showing the output you configure as below example:

Screenshot 2022-01-10 at 1.18.37 PM.png

If it's not showing any echo output or the output is different from what you expected then the variable may be using a secure variable or you have a conflict variable that you may have configured in the deployment variable or the workspace variable.

I hope this helps.

Cheers,
Syahrul

senad87 January 19, 2022

Thank you Syahrul! 

It was a missunderstaning on my part. I was expecting that deployment variables are accessible acros all steps.

I solved it by creating repository level variables, since those can be used in all steps.

Thanks again, cheers!

 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events