如何在 Azure DevOps 的构建管道中启用 Oauth 身份验证

how to enable Ouath authentication in build pipeline of Azure DevOps

我的构建失败并出现以下错误。我想在管道中启用此选项。 有人可以帮我解决这个问题吗?我可以在发布管道的附加选项部分 select 这个选项。但不确定如何在构建管道中执行此操作。

##[错误]未找到 OAuth 令牌。确保在构建定义中启用 'Allow Scripts to Access OAuth Token'。

##[error]OAuth token not found. Make sure to have 'Allow Scripts to Access OAuth Token' enabled in the build definition.

对于这个问题,在代理作业中勾选下图所示的选项

对于 yaml 管道,在脚本/任务级别,例如 PowerShell:

- powershell: ./build.ps1
  env:
      system_accesstoken: $(System.AccessToken)

这里是ticket你可以参考

更新:

  - task: GitCopyDiff@1
    inputs:
      destination: '$(Build.ArtifactStagingDirectory)/diff'
      changeType: 'M'
    env: 
     SYSTEM_ACCESSTOKEN: $(system.accesstoken)