如何允许脚本从Yaml构建访问OAuth令牌 [英] How to allow scripts to access OAuth token from yaml builds
问题描述
我的构建脚本使用SYSTEM_ACCESSTOKEN
环境变量.
My build script uses the SYSTEM_ACCESSTOKEN
environment variable.
在设计器版本定义中,我检查了允许脚本访问OAuth令牌,一切正常.
In the designer build definition I checked Allow scripts to access the OAuth token and everything works.
在复制设计器生成的YAML定义之后,我无法访问SYSTEM_ACCESSTOKEN
环境变量.
After copying the designer generated YAML definition I cannot access the SYSTEM_ACCESSTOKEN
environment variable.
如何允许我的YAML版本访问OAuth令牌?
How do I allow my YAML build to access the OAuth Token?
这是我的azure-pipelines.yaml:
This is my azure-pipelines.yaml:
queue:
name: Hosted VS2017
steps:
- checkout: self
lfs: true
persistCredentials: true
- powershell: ./build.ps1
推荐答案
I found the solution in the Pipeline Variable docs: The variable must be declared in YAML.
在管道级别上用于所有作业/任务:
At pipeline level for all jobs / tasks:
variables:
system_accesstoken: $(System.AccessToken)
jobs:
job: ...
或者在脚本/任务级别,例如PowerShell:
Or at script / task level for example PowerShell:
- powershell: ./build.ps1
env:
system_accesstoken: $(System.AccessToken)
这篇关于如何允许脚本从Yaml构建访问OAuth令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!