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,364,059
Community Members
 
Community Events
168
Community Groups

Passed variables to npm script are empty

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

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 Jan 09, 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

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

Atlassian Community Events