I am trying to run this command in Azure DevOps Build pipeline:
npm run coverage
This command requires 2 env variables available in order to complete successfully.
Earlier, I was using the NPM Task for the same but there is no way we can pass env variables in that task.
- task: Npm@1
displayName: npm test
inputs:
command: custom
workingDir: $(Build.SourcesDirectory)
verbose: false
customCommand: run coverage
So I have changed it to Script step like following:
- script: 'npm run coverage'
workingDirectory: $(Build.SourcesDirectory)
displayName: 'npm test'
env:
CLASS_PATH: './test/mock/'
MONGO_PATH: '../../../services/mock/'
But it's not picking up these 2 env variables and the task is failing making the entire build fail.
I have also tried adding a Script task which sets these 2 env variables prior to run coverage command like following:
- script: |
export CLASS_PATH='./test/mock/'
export MONGO_PATH='../../../services/mock/'
echo $CLASS_PATH
echo $MONGO_PATH
It prints the set env variables, but the next step which is npm run coverage
is not getting those env variables.
Can anyone please help passing these env variables to the npm command?
My Pipeline:
trigger:
branches:
include:
- 'master'
variables:
class_path: './test/mock/'
mongo_path: '../../../services/mock/'
pool: 'self-hosted'
stages:
- stage: Build
displayName: Build and push stage
jobs:
- job: Build
displayName: Build
pool:
name: 'self-hosted'
steps:
- script: |
export CLASS_PATH='./test/mock/'
export MONGO_PATH='../../../services/mock/'
echo $CLASS_PATH
echo $MONGO_PATH
- script: 'npm run coverage'
workingDirectory: $(Build.SourcesDirectory)
displayName: 'npm test'
env:
CLASS_PATH: $(class_path)
MONGO_PATH: $(mongo_path)