3

Used below scripts in package.json to set NODE_ENV while creating the build.

"scripts": {
    "build-dev": "set NODE_ENV=development && webpack --config webpack.config.prod",
    "build-client": "set NODE_ENV=production && webpack --config webpack.config.prod",
}

locally if I run "npm run build-dev or build-client" its working correctly and able to read correct NODE_ENV on webpack.config.common.js file.

But if I try same command to create build on Azure pipeline then process.env.NODE_ENV returning as undefined

Not sure on Azure why "process.env.NODE_ENV" returning as undefined. Can someone please help to understand and what needs to be done on Azure to read correct NODE_ENV which was set at the Build time.

Below are the pipeline details

# Node.js
# Build Data Direct UI project with npm.
# https://learn.microsoft.com/azure/devops/pipelines/languages/javascript

trigger: none
#- master

pool: AGENTS

variables:
  system.debug : true
  
steps:

- task: Docker@0
  displayName: 'Build an Image'
  inputs:
    azureSubscription: 'CIS-DEV-001-SC'
    azureContainerRegistry: `{"loginServer":"acrncusd.azurecr.io", "id" : "acrncusd"}`



- task: Docker@0
  displayName: 'Push Image'
  inputs:
    azureSubscription: 'CIS-DEV-001-SC'
    azureContainerRegistry: `{"loginServer":"acrncusd.azurecr.io", "id" :  
    "acrncusd"}`
    action: 'Push an image'
    imageName: `$(Build.Repository.Name):$(Build.BuildId)`
sagar
  • 464
  • 4
  • 13

1 Answers1

0

If you're using windows-hosted agent, we should remove the whitespace before and after the &&.

Try:

"scripts": {
    "build-dev": "set NODE_ENV=development&&webpack --config webpack.config.prod",
    "build-client": "set NODE_ENV=production&&webpack --config webpack.config.prod",
}
LoLance
  • 25,666
  • 1
  • 39
  • 73
  • Hi Lance, yes already tried adding and removing white space before and after && but on Azure pipeline build while reading process.env.NODE_ENV inside webpack.config.js file returning undefined. If I try to build it locally able to access correct process.env.NODE_ENV. – sagar Aug 18 '20 at 08:49
  • @sagar Which agent do you use, windows or linux, microsoft-hosted or self-hosted? Please consider adding the details about your build definitions and which step does the error comes from so that I can check for you directly. – LoLance Aug 18 '20 at 09:28
  • Thanks Lance, we are using Linux agent and its self hosted. and what i am trying to do here at the build time based on the NODE_ENV read the .env file which contains the env detail info. Please let me know if need more info. – sagar Aug 19 '20 at 09:52
  • Could you share some details about your pipeline like [this thread](https://stackoverflow.com/questions/63372045/azure-pipelines-encountered-errors-while-parsing-pipeline-yaml-unique-job-nam/63373858#63373858), I need some details to reproduce your issue. And what's the result if you use the pipeline using windows-latest agent, can the same task succeed? – LoLance Aug 19 '20 at 09:59
  • As you requested below are the details: trigger: none variables: system.debug : true steps: - task: Docker@0 displayName: 'Build an Image' inputs: azureSubscription: '001-SC' azureContainerRegistry: '{"loginServer":"acrsd.azurecr.io", "id" : "acrsd"}' - task: Docker@0 displayName: 'Push Image' inputs: azureSubscription: '001-SC' azureContainerRegistry: '{"loginServer":"acrsd.azurecr.io", "id" : "acrsd"}' action: 'Push an image' imageName: '$(Build.Repository.Name):$(Build.BuildId)' – sagar Aug 19 '20 at 15:00
  • How does your dockerfile looks like? It seems this issue occurs in docker build step. – LoLance Aug 24 '20 at 09:42
  • Actually its as per the format you mentioned in above comment "this thread", but in comment we can put max 550 chars, so pasted like above by removing white spaces. – sagar Aug 24 '20 at 09:50
  • @sagar It's recommended to add the details in question. You can see the `edit` button below your question, you can edit the question to add the details~ – LoLance Aug 24 '20 at 10:02
  • thanks for info. Updated pipeline details in question. Please let me know if need more info. – sagar Aug 25 '20 at 08:30
  • What's the result if you build the docker image locally like [this](https://docs.docker.com/engine/reference/commandline/build/), I think maybe the issue is the built image itself. – LoLance Aug 25 '20 at 10:01