Jon*_*ist 5 rest powershell azure azure-devops
Azure DevOps 服务 REST API 5.0 - Wiki 页面
每当存储库发生更改时,我都会尝试动态更新 Azure DevOps Wiki 页面,并在顶部显示最新的提交。当我尝试将提交历史记录放入 Wiki 页面时,正文中的内容字段为空。
该请求是通过 Powershell 完成的,如下所示:
function postToWiki($Commits) {
$wikiUrl = "https://dev.azure.com/$organization/$project/_apis/wiki/wikis/Ekonomiredovisning.wiki/pages?path=MyWikiPage&api-version=5.0"
$Etag = getWikiPageVersion
$headers = @{
Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN";
'If-Match' = $Etag}
$body = @{ content = $Commits }
$json = $body | ConvertTo-Json
Invoke-WebRequest -Uri $wikiUrl -Headers $headers -Body $json -ContentType "application/json" -Method Put
}
Run Code Online (Sandbox Code Playgroud)
可能有用的其他信息:
小智 1
我今天也有同样的问题。我的正文包含特殊的 HTML 字符,这些字符不会在请求中转义。
\n\n尝试转义特殊字符 (\xc3\xa9\xc3\xa8...)。\n在 PowerShell 中,您可以使用以下程序集:
\n\nAdd-Type -AssemblyName System.Web\n$encodedBody = [System.Web.HttpUtility]::HtmlEncode($Commits)\n
Run Code Online (Sandbox Code Playgroud)\n\n结果:
\n\n\n# Construct the wiki REST URI \n# $uri = $WikiUri +$WikiPath + $($contentPackage.version)\n$uri = "$($env:WikiUri)$($contentPackage)&api-version=5.0"\n\n# Encode and convert to json\nAdd-Type -AssemblyName System.Web\n$encodedContent = [System.Web.HttpUtility]::HtmlEncode($content)\n\n$data = @{ Content=$encodedContent; } | ConvertTo-Json;\n\n# Set Request\n$params = @{uri = "$($uri)";\n Method = \'PUT\';\n Headers = $header;\n ContentType = "application/json";\n Body = $data;\n}\n\n# Call\nInvoke-WebRequest @params \n
Run Code Online (Sandbox Code Playgroud)\n
归档时间: |
|
查看次数: |
629 次 |
最近记录: |