在 Azure DevOps 中,我遇到了无法通过 API 创建项目 Wiki 页面的问题。我尝试使用 REST API 创建 Project Wiki 页面,但始终收到 404 HTTP 错误。我正在使用带有“curl”命令的 bash 任务从构建管道执行此操作。
这是我正在使用的管道:
trigger:
branches:
include:
- '*'
jobs:
- job: WikiJob
pool:
vmImage: 'ubuntu-latest'
steps:
- bash: |
#!/bin/bash
set -e
API_VERSION=7.1
# Get the current project from the pipeline context
project=$(System.TeamProject)
# Define the Wiki details
wikiRepo=${project}.wiki
# Use the pipeline's built-in PAT as the Personal Access Token
personalAccessToken=$(System.AccessToken)
url="$SystemURI/$project/_apis/wiki/wikis/$wikiRepo/pages?path=my_page&api-version=$API_VERSION"
echo URL $url
# Prepare the content update request
updateContent='{"content":"Foo Bar"}'
response=$(curl -i -X PUT \
-H "Authorization: Bearer $personalAccessToken" \
-H "Content-Type: application/json" \
--data "$updateContent" \
--url "$url")
echo response $response
env:
CollectionUri: $(System.CollectionUri)
SystemURI: $(System.CollectionUri)
我可以确认变量已正确填充,并且 $wikiRepo 中定义的 Wiki 确实存在。
但是,我始终收到 HTTP 代码 404 和以下错误消息:
{"$id":"1","innerException":null,"message":"TF401019: The Git repository with name or identifier e2b297b8-965a-4a29-8541-bfbc0e6314a0 does not exist or you do not have permissions for the operation you are attempting.","typeName":"Microsoft.TeamFoundation.Git.Server.GitRepositoryNotFoundException, Microsoft.TeamFoundation.Git.Server","typeKey":"GitRepositoryNotFoundException","errorCode":0,"eventId":3000}
错误中提到的Git repo在项目中不存在。
构建服务用户具有贡献者权限,这应该允许其添加和编辑 Wiki 页面。
示例中的 Wiki 页面
my_page
不存在。我希望创建该页面。
在某些情况下,即使构建服务被添加为贡献者,也无法访问 wiki。尝试使用 PAT 而不是
System.AccessToken
。也许这是否是一个错误..,但这是一个在这里添加的好案例:https://developercommunity.visualstudio.com/AzureDevOps