首页 > 解决方案 > DevOps Pipeline 如何修复此“允许脚本访问 OAuth 令牌”

问题描述

我有一个 Azure DevOps 管道,我想标记 Azure Git 存储库

task: AssembyInfoReader@2
 displayName: Set Version numbers
 inputs:
   searchPattern: 'JLReyLibrary/Properties/GlobalAssemblyInfo.cs'

获取程序集信息变量。

然后这个任务会导致错误:

task: GitTag@2
 displayName: Tag Repo to $(AssemblyInfo.AssemblyInformationVersion)
 inputs:
   tag: '$(AssemblyInfo.AssemblyInformationalVersion)'
   forceTagCreation: true
##[error]OAuth token not found. Make sure to have 'Allow Scripts to Access OAuth Token' enabled in the build definition.

如何设置 OAuth 令牌?

澄清

我尝试了下面的建议。

现在我有以下问题。

我找到了`DevOps->Organizational Settings->OAuth Configurations

我仍然收到以下错误消息:

Allow Scripts to Access OAuth Token

标签: azure-devops

解决方案


您需要将此添加到任务中:

env:
  System_AccessToken: $(System.AccessToken)

所以,在你的情况下:

- task: GitTag@2
  displayName: Tag Repo to $(AssemblyInfo.AssemblyInformationVersion)
  inputs:
    tag: '$(AssemblyInfo.AssemblyInformationalVersion)'
    forceTagCreation: true
  env:
     System_AccessToken: $(System.AccessToken)

推荐阅读