azure-devops - 在 yaml 文件中调用管道变量(Repos)
问题描述
我有以下情况:在 Azure Repos 中,我需要放置需要放置 OAuth 凭据的 yaml 文件,并且在发布管道任务中发布 PowerShell 脚本时调用该 yaml 文件。我的问题是,当我试图将这些凭据保存在管道变量中并通过 $(OAuth) 将它们引用到 yaml 文件中时,我需要将我在 Repos yaml 文件下提供的 OAuth 屏蔽为纯文本。甚至可以使用管道变量在 Repos 下的 yaml 文件中屏蔽 OAuth?请帮忙。
解决方案
当我试图将这些凭据保存在管道变量中并通过 $(OAuth) 在 yaml 文件中引用它们时不起作用。
不能$(OAuth)
在 PowerShell 中直接引用秘密管道变量。
下面是一个关于使用mySecret
PowerShell 中调用的 secert 管道变量的示例。与普通管道变量不同,没有名为 MYSECRET 的环境变量。单击链接以获取更多详细信息。
variables: GLOBAL_MYSECRET: $(mySecret) # this will not work because the secret variable needs to be mapped as env GLOBAL_MY_MAPPED_ENV_VAR: $(nonSecretVariable) # this works because it's not a secret. steps: - powershell: | Write-Host "Using an input-macro works: $(mySecret)" Write-Host "Using the env var directly does not work: $env:MYSECRET" Write-Host "Using a global secret var mapped in the pipeline does not work either: $env:GLOBAL_MYSECRET" Write-Host "Using a global non-secret var mapped in the pipeline works: $env:GLOBAL_MY_MAPPED_ENV_VAR" Write-Host "Using the mapped env var for this task works and is recommended: $env:MY_MAPPED_ENV_VAR" env: MY_MAPPED_ENV_VAR: $(mySecret) # the recommended way to map to an env variable
上述脚本中任务的输出如下所示:
Using an input-macro works: *** Using the env var directly does not work: Using a global secret var mapped in the pipeline does not work either: Using a global non-secret var mapped in the pipeline works: foo Using the mapped env var for this task works and is recommended: ***
推荐阅读
- ruby-on-rails - 多个方法(?)和对象(即 num.to_s.chars.map{|x| x.to_i**2}.join.to_i)的规则是什么?
- caching - 您如何在客户端/浏览器上存储自定义 404 页面以在没有互联网连接时显示?
- git - 加载 bitbucket 服务器时出现致命错误
- spring-webflux - 在 Spring Reactor 中使用 BaseSubscriber 钩子与订阅者方法有什么好处?
- python - 嵌套 for 循环产生的值比预期的多-Python
- flutter - 在 Flutter 上实现配置文件弹出
- javascript - 如何在 reactjs 中设置状态数据
- assembly - 如果没有它仍然可以工作,我是否需要在 NASM 汇编函数中添加行 'mov ebp, esp'?
- python - ValueError:类的数量必须大于一;上了一堂课
- python - 使用另一个值列表设置 Pandas 数据框值