0

I'm attempting to run an Azure Pipeline, with some environment variables defined in the pipeline itself, and I am using the Maven Build task to build my project with Maven to launch various tests. A JS file automatically runs before each test, and I'm supposed to configure these variables in this file, which would make them available to use in the tests themselves. Currently, I have something like this:

# azure-pipelines.yml

trigger:
- none

pool:
  vmImage: ubuntu-latest

variables:
- name: user_secret
  value: "foo"

steps:

 - task: Maven@3
   inputs:
     mavenPomFile: 'pom.xml'
     goals: test
     publishJUnitResults: true
     testResultsFiles: '**/surefire-reports/TEST-*.xml'
     javaHomeOption: 'JDKVersion'
     mavenVersionOption: 'Default'
     mavenAuthenticateFeed: false
     effectivePomSkip: false
     sonarQubeRunAnalysis: false
// config.js

function fn(){
    return  {
        secret: user_secret
    };
}

The error I get is "user_secret" is not defined

I am being told I can debug it locally because the pipeline is providing the values as environment variables, and that I should be able to validate that locally by setting the variables when I run my code. Unfortunately, I can't figure out how to do it.

Similar to the above example, I also tried to get the variable process.env.user_secret, but this didn't work for me either.

How can I access Azure variables in my code?

sprogissd
  • 2,755
  • 5
  • 24
  • 45
  • You can refer to [Can variables in Azure Pipelines be used in NodeJS code?](https://stackoverflow.com/questions/54215041/can-variables-in-azure-pipelines-be-used-in-nodejs-code), [How to apply a variable in Azure Pipelines to a node app during build](https://stackoverflow.com/questions/66537243/how-to-apply-a-variable-in-azure-pipelines-to-a-node-app-during-build) and [How to use Azure Pipeline variable in JavaScript (React) project?](https://stackoverflow.com/questions/64058755/how-to-use-azure-pipeline-variable-in-javascript-react-project) – Ecstasy May 05 '22 at 05:00
  • Does this answer your question? [How to use Azure Pipeline variable in JavaScript (React) project?](https://stackoverflow.com/questions/64058755/how-to-use-azure-pipeline-variable-in-javascript-react-project) – Ecstasy May 10 '22 at 04:16

0 Answers0