0

在此处输入图像描述我为定义了运行管道的用户创建了身份验证令牌以及所有权限

4

1 回答 1

0

如果您Run with Build Agent Credentials在任务中检查为身份验证。并且构建帐户在Wiki 安全页面{ProjectName} build service ({OrganizationName})中被授予读取和贡献权限。

但是您仍然遇到上述错误。这可能是因为您在 Azure DevOps 服务器计算机中打开了 IIS 基本身份验证。在 Windows 计算机上启用 IIS 基本身份验证时,它会阻止您使用个人访问令牌 (PAT) 作为身份验证机制。见这里

我们建议您在使用 Azure DevOps Server 时始终关闭 IIS 基本身份验证。只有在必要时才应启用 IIS 基本身份验证。在 Windows 计算机上启用 IIS 基本身份验证时,它会阻止您使用个人访问令牌 (PAT) 作为身份验证机制。

作为解决方法,您可以在启用 IIS 基本身份验证时向 Git 请求添加一个额外的标头,其中包含“user:PAT”的 base 64 编码:

因此,您可以在 powershell 任务中运行纯 git 命令来更新您的 wiki 存储库,而不是使用基于 git 的 wiki 更新程序任务。请参阅以下 powershell 任务中的示例脚本(yaml 格式):

steps:
- powershell: |
  
   git config --global user.email "your@eamil.com"
   git config --global user.name "name"
   
   $MyPat = "$(system.accesstoken)"
   $B64Pat = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(":$MyPat"))
   
   #clone the wiki repo
   git -c http.extraHeader="Authorization: Basic $B64Pat" clone https://server/collection/_git/Document.wiki -q
   
   cd Document.wiki

   #add a new file 
   echo  echo "some-text"  > addnew.md
   
   git add .
   git commit -m message

   #push to wiki repo
   git -c http.extraHeader="Authorization: Basic $B64Pat" push https://server/collection/_git/Document.wiki -q
  displayName: 'update wiki'

在这里查看更多信息。

为了$(system.accesstoken)在上述脚本中使用构建代理 OAuth 令牌。您需要单击Agent job 1并检查选项Allow scripts to access the OAuth token

在此处输入图像描述

于 2020-10-08T03:19:13.180 回答