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

查看:22
本文介绍了如何允许脚本从 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

推荐答案

我在 管道变量文档:变量必须在 YAML 中声明.

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天全站免登陆