Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set env variable for NPM build step

Using terminal on my dev machine, I can do this...

SOME_VARIABLE=http://localhost:3000/ npm start

... and SOME_VARIABLE is accessible in the code using...

process.env.SOME_VARIABLE

Using the NPM build step in Azure DevOps, how do I set the same environment variable?

I can't add the variable in the "Command and arguments" text field because they're added after the generated call to npm.

Furthermore, if I copy the command that works on my dev machine and run it from a command line task, it won't accept the command format, I presume because it's Windows.

like image 834
Ian Warburton Avatar asked Sep 11 '26 15:09

Ian Warburton


1 Answers

the existing answer is not what you would want, probably. what you want to do is go to build setting > variables and declare it there

https://learn.microsoft.com/en-us/azure/devops/pipelines/build/options?view=vsts&tabs=yaml#variables

like image 91
4c74356b41 Avatar answered Sep 15 '26 09:09

4c74356b41