如何允许脚本从Yaml构建访问OAuth令牌 [英] How to allow scripts to access OAuth token from yaml builds

查看:81
本文介绍了如何允许脚本从Yaml构建访问OAuth令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的构建脚本使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆