[英]How do I add environment variables to a container with azure build yml?
Trying to deploy an app to kubernetes using azure.尝试使用 azure 将应用程序部署到 kubernetes。 I have a build pipeline yml file and in the pipeline i've set a variable called "discordToken".
我有一个构建管道 yml 文件,在管道中我设置了一个名为“discordToken”的变量。 I tried setting it two different ways, one is called discordToken and the other is MY_MAPPED_ENV_VAR.
我尝试以两种不同的方式设置它,一种称为 discordToken,另一种称为 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?我应该如何设置环境变量?
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.据我所知,如果直接在Powershell任务中设置环境变量(env:xxx),该变量只能被当前任务使用。
You could try to set the variables with script , then the variables could be used by following task.您可以尝试使用 script 设置变量,然后可以通过以下任务使用这些变量。
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 :您可以在Settings -> Variables中设置参考变量:
Here is a ticket about set environment variables in dockerfile , it may help you.这是一张关于在 dockerfile 中设置环境变量的票,它可能会对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.