skip to Main Content

I am trying to run a node application in azure devops and I am struggling with the following issue. I need to set an environment variable that is picked up with the code, but it looks like I am no hitting the point

Yaml:

pool:
  vmImage: 'ubuntu-latest'

parameters:
- name: VERBOSE
  displayName: 'Verbose'
  type: boolean
  default: false

steps:
- task: NodeTool@0
  inputs:
    versionSpec: '16.16.x'
  displayName: 'Install Node.js'

- task: Npm@1
  inputs:
    command: install
    workingDir: '$(Build.SourcesDirectory)/pipelines/schemas'
    verbose: false
    customRegistry: useNpmrc
  displayName: 'Install npm'

- task: CmdLine@2
  env:
    VERBOSE: ${{ parameters.VERBOSE }}
  inputs:
    script: 'node app.js' 
    workingDirectory: '$(Build.SourcesDirectory)/pipelines/schemas'
  displayName: 'Run app.js'

at the first line of app.js I set a console.log(process.env["VERBOSE"]), but nothing is displayed.
Do you know what I am missing?

2

Answers


  1. I would first check whether it fails on assignment or evaluation.

    If you change the default parameter value, is it reflected?

    If not, fix that first. If yes, then start figuring out how to assign the parameter correctly. Right now it’s impossible to tell which of these needs fixing.

    Login or Signup to reply.
  2. This is the YAML on my side:

    trigger:
    - none
    
    
    parameters:
    - name: VERBOSE
      displayName: 'Verbose'
      type: boolean
      default: false
    
    pool:
      vmImage: ubuntu-latest
    
    steps:
    - task: CmdLine@2
      inputs:
        script: 'ls'
    - task: CmdLine@2
      env:
        VERBOSE: ${{ parameters.VERBOSE }}
      inputs:
        script: 'node app.js' 
        workingDirectory: '$(Build.SourcesDirectory)/pipelines/schemas'
      displayName: 'Run app.js'
    

    My repo structure:

    enter image description here

    I can get the value successfully:

    enter image description here

    Try to use the above simply demo, could the value appear on your side?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search