401 errors on deploy step
Asked by Roy Chapman:

We have a Bamboo plan with the following task

npm run prep-deploy \&\& node deploy.js --destination cys --fullDeploy

The deploy.js file contains this section

```
var?config?= {

??username:?process.env.SAP_USERNAME,

??password:?process.env.SAP_PASSWORD,

??path:?'./dist',

??host:?'https://crmsanproj.svcrm.jlrcloud.com',

??base:?'/sap/bc/bsp_dev/sap/zcrm_jlr_dev/',

}
```

I have the following variables setup at the plan level

env.SAP_USERNAME

env.SAP_PASSWORD

When we execute the command I get these errors

```
build?? 22-Aug-2022 15:10:47?? Uploading: ./dist/assets/svg/user-landrover.svg STATUS: 401 TIME: 15:10 47

build?? 22-Aug-2022 15:10:47?? to : https://crmsanproj.svcrm.jlrcloud.com/sap/bc/bsp_dev/sap/zcrm_jlr_dev/assets/svg/user-landrover.svg

build?? 22-Aug-2022 15:10:47?? 401: null

build?? 22-Aug-2022 15:10:47?? date: Mon, 22 Aug 2022 15:10:47 GMT

build?? 22-Aug-2022 15:10:47?? server: Apache

build?? 22-Aug-2022 15:10:47?? content-type: text/html; charset=utf-8

build?? 22-Aug-2022 15:10:47?? content-length: 1248

build?? 22-Aug-2022 15:10:47?? sap-system: CYS

build?? 22-Aug-2022 15:10:47?? www-authenticate: Basic realm="SAP NetWeaver Application Server [CYS/100]"

build?? 22-Aug-2022 15:10:47?? sap-server: true

build?? 22-Aug-2022 15:10:47?? sap-perf-fesrec: 2427.000000

build?? 22-Aug-2022 15:10:47?? content-security-policy: frame-ancestors self https://*.liveperson.net https://*.svcrm.jlrcloud.com https://*.svcrm.jlrint.com;

build?? 22-Aug-2022 15:10:47?? connection: close


```

Obviously 401 is an authentication error. On the server side we are seeing a message indicating an issue with the username, password or client.

The variables env.SAP_USERNAME \& env.SAP_PASSWORD describe the username and password and the section "Basic realm="SAP NetWeaver Application Server \[CYS/100" suggests we are passing the client correctly.

At present I am stumped and looking for more debug information. For example I want to see if the username and password is passed with the npm command? If there a log or a debug option that would expose this information?


Answers:
author: Eduardo Alvarenga
body: Hello [@Roy Chapman](/t5/user/viewprofilepage/user-id/5014576),

Welcome to **Atlassian Community!**

If you want to use environment variables in Bamboo, you need to adhere to the Bamboo format.

For example, **env.SAP_USERNAME** would be converted to:

    ${bamboo.env.SAP_USERNAME}

or

    ${bamboo_env_SAP_USERNAME}

..if used in a script task.

More information about how Bamboo prefixes its variables:

* [Bamboo variables](https://confluence.atlassian.com/bamboo/bamboo-variables-289277087.html)

Kind regards,

Eduardo Alvarenga  
Atlassian Support APAC

**--please don't forget to Accept the answer if the reply is helpful--**

comments: author: Roy Chapman
body: Eduardo,

We have made these changes to the deploy.js file

```
var config = {

  username: bamboo.env.SAP_USERNAME,

  password: bamboo.env.SAP_PASSWORD,

  path: './dist',

  host: 'https://crmsanproj.svcrm.jlrcloud.com',

  base: '/sap/bc/bsp_dev/sap/zcrm_jlr_dev/',

}
```

(previously the entries were prefixed process) When I run the job I now see

```
error	23-Aug-2022 15:50:06	/home/bamboo/agent1-home/xml-data/build-dir/SVCRM-CJU-JOB1/deploy.js:39error	23-Aug-2022 15:50:06	  username: bamboo.env.SAP_USERNAME,error	23-Aug-2022 15:50:06	            ^error	23-Aug-2022 15:50:06	error	23-Aug-2022 15:50:06	ReferenceError: bamboo is not definederror	23-Aug-2022 15:50:06	    at Object.<anonymous> (/home/bamboo/agent1-home/xml-data/build-dir/SVCRM-CJU-JOB1/deploy.js:39:13)error	23-Aug-2022 15:50:06	    at Module._compile (module.js:653:30)error	23-Aug-2022 15:50:06	    at Object.Module._extensions..js (module.js:664:10)error	23-Aug-2022 15:50:06	    at Module.load (module.js:566:32)error	23-Aug-2022 15:50:06	    at tryModuleLoad (module.js:506:12)error	23-Aug-2022 15:50:06	    at Function.Module._load (module.js:498:3)error	23-Aug-2022 15:50:06	    at Function.Module.runMain (module.js:694:10)error	23-Aug-2022 15:50:06	    at startup (bootstrap_node.js:204:16)error	23-Aug-2022 15:50:06	    at bootstrap_node.js:625:3
```

As indicated, the variables are saved in Bamboo they are automatically prefixed with env (for example env.SAP_USERNAME).

What am I missing?

Roy


author: Eduardo Alvarenga
body: Thank you [@Roy Chapman](/t5/user/viewprofilepage/user-id/5014576). Please keep us posted!

Eduardo Alvarenga  
Atlassian Support APAC


author: Roy Chapman
body: Eduardo,

I edit the above. Thoughts?

Roy


author: Eduardo Alvarenga
body: Hey [@Roy Chapman](/t5/user/viewprofilepage/user-id/5014576)

node.js uses environment variables in the following format:

```
process.env.<MY_VARIABLE>
```

So considering the variable in Bamboo is called **SAP_USERNAME**please try:

```
process.env.bamboo_SAP_USERNAME
```

Kind regards,

Eduardo Alvarenga  
Atlassian Support APAC

**--please don't forget to Accept the answer if the reply is helpful--**


author: Roy Chapman
body: Perfect. Working now