如何从管道访问环境变量并将其传递到发布管道
How to access an environment variable from a pipeline and pass it to a release pipeline
我有一个自动构建和部署的应用程序。
当前流量:
Git push -> Azure (build) pipeline creates artifact -> Azure Release pipeline picks up artifact and deploys it on a DigitalOcean server using "copy files" and then goes into the command line.
我需要在命令行中进行一些自动配置,这需要一个对于每个构建都是唯一的环境变量。
如何从管道访问环境变量并以某种方式将其传递到发布管道,以便我可以在命令行的命令中使用它?
用于导出环境变量的 NPM 命令:
"releasecustom": "export VUE_APP_SENTRY_RELEASE=$(UniqueValue) && node
scripts/createreleasesentry.js && npm run build && node scripts/finalizereleasesentry.js",
我有点害怕这不是开箱即用的支持。您可以做的是使用例如 powershell 任务 (or use extension for this) 在文件中记下您的值。
New-Item -Path $(Build.ArtifactStagingDirectory)/vardrop -Name "variables.txt" -ItemType "file" -Value "This is a text string."
然后你必须将其发布为工件。
- task: PublishBuildArtifacts@1
inputs:
pathToPublish: '$(Build.ArtifactStagingDirectory)/vardrop'
artifactName: vardrop
接下来在发布管道中,您需要下载工件并读取此文件并设置变量(使用 powershell 任务)。
这里有一个示例,但是如果文件中的值多于一个值,则需要拆分它们并分别分配。
echo "##vso[task.setvariable variable=dp]$(cat $(System.ArtifactsDirectory)/vardrop/variables.txt)"
我有一个自动构建和部署的应用程序。
当前流量:
Git push -> Azure (build) pipeline creates artifact -> Azure Release pipeline picks up artifact and deploys it on a DigitalOcean server using "copy files" and then goes into the command line.
我需要在命令行中进行一些自动配置,这需要一个对于每个构建都是唯一的环境变量。
如何从管道访问环境变量并以某种方式将其传递到发布管道,以便我可以在命令行的命令中使用它?
用于导出环境变量的 NPM 命令:
"releasecustom": "export VUE_APP_SENTRY_RELEASE=$(UniqueValue) && node
scripts/createreleasesentry.js && npm run build && node scripts/finalizereleasesentry.js",
我有点害怕这不是开箱即用的支持。您可以做的是使用例如 powershell 任务 (or use extension for this) 在文件中记下您的值。
New-Item -Path $(Build.ArtifactStagingDirectory)/vardrop -Name "variables.txt" -ItemType "file" -Value "This is a text string."
然后你必须将其发布为工件。
- task: PublishBuildArtifacts@1
inputs:
pathToPublish: '$(Build.ArtifactStagingDirectory)/vardrop'
artifactName: vardrop
接下来在发布管道中,您需要下载工件并读取此文件并设置变量(使用 powershell 任务)。
这里有一个示例,但是如果文件中的值多于一个值,则需要拆分它们并分别分配。
echo "##vso[task.setvariable variable=dp]$(cat $(System.ArtifactsDirectory)/vardrop/variables.txt)"