0

Trying to deploy an app to kubernetes using azure. I have a build pipeline yml file and in the pipeline i've set a variable called "discordToken". I tried setting it two different ways, one is called discordToken and the other is MY_MAPPED_ENV_VAR. in my node project i'm doing

console.log( process.env.discordToken )
console.log( process.env.MY_MAPPED_ENV_VAR )

but everything keeps coming back as undefined.

stages:
- stage: Build
  displayName: Build stage
  jobs:  
  - job: Build
    displayName: Build
    pool:
      vmImage: $(vmImageName)
      environment:
        discordToken: $(discordToken)
    steps:
    - powershell: |
      env:
        MY_MAPPED_ENV_VAR: $(discordToken)
    - task: Docker@2
      displayName: Build and push an image to container registry
      inputs:
        command: buildAndPush
        repository: $(imageRepository)
        dockerfile: $(dockerfilePath)
        containerRegistry: $(dockerRegistryServiceConnection)
        tags: |
          $(tag)

How should i be setting the environment variables?

Enter Name
  • 13
  • 1
  • 5

1 Answers1

0

As far as I know, if you directly set the environment variable (env:xxx) in Powershell Task, the variable can only be used by the current task.

You could try to set the variables with script, then the variables could be used by following task.

For example:

- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: |
      # Write your PowerShell commands here.
      echo "##vso[task.setvariable variable=MY_MAPPED_ENV_VAR]$(discordToken)"

You could set the reference variable in Settings -> Variables:

Variables

Here is a ticket about set environment variables in dockerfile, it may help you.

Kevin Lu-MSFT
  • 20,786
  • 3
  • 19
  • 28