问题描述
我创建了身份验证令牌以及已定义运行管道的用户的所有权限
解决方法
如果您在任务中选中Run with Build Agent Credentials
作为“身份验证”。并在 Wiki安全性页面中向构建帐户{ProjectName} build service ({OrganizationName})
授予了读取和贡献权限。
但是您仍然遇到上述错误。可能是因为您在Azure DevOps Server计算机中启用了IIS基本身份验证。在Windows计算机上启用IIS基本身份验证后,它将阻止您使用个人访问令牌(PAT)作为身份验证机制。参见here。
我们建议您在使用Azure DevOps Server时始终关闭IIS基本身份验证。仅在必要时才启用IIS基本身份验证。在Windows计算机上启用IIS基本身份验证后,它将阻止您使用个人访问令牌(PAT)作为身份验证机制。
作为解决方法,您可以在启用IIS基本身份验证时向Git请求添加额外的标头,其中包括以“ user:PAT”为基数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'
检查here以获得更多信息。
为了在上述脚本中使用Build Agent OAuth令牌$(system.accesstoken)
。您需要单击Agent job 1
并选中选项Allow scripts to access the OAuth token