Publishing release notes to Wiki during build in ADO pipeline

83 Views Asked by At

I generate release note automatically when ever the build is triggered. My aim is to create a wiki page from the release note. I followed the powershell script on https://scatteredcode.net/publishing-release-notes-to-tfs-vsts-wiki-during-release/

The script ran successfully but the wiki sub page did not get created. The aim is to create a sub page "test" under the PartsUnlimitedWiki page.

wikiPath: https://dev.azure.com/xxxx/MyDevOpsProject/_apis/wiki/wikis/MyDevOpsProject_wiki/pages?path=PartsUnlimitedWiki/test&api-version=6.0"

PowerShell Script

enter image description here

1

There are 1 best solutions below

0
Bright Ran-MSFT On BEST ANSWER

I tested with below PowerShell script, and it can work will to create/update the sub-page with the content. You can reference it to update your script.

$pat = "{Personal Access Token}"
$base64Token = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f "", $pat)))

$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", ("Basic {0}" -f $base64Token))
$headers.Add("Content-Type", "application/json")

$uri = "https://dev.azure.com/{organization}/{project}/_apis/wiki/wikis/{wiki-name}/pages?path=/parent-page-name/sub-page-name&api-version=7.0"

$content = [IO.File]::ReadAllText("path/to/release-notes.md")
$body = @{content = $content} | ConvertTo-Json -Depth 10

Invoke-RestMethod -Method PUT -Uri $uri -Headers $headers -Body $body

When you run the script in Azure Pipelines, the value of authorization token can be either your PAT (Personal Access Token) or the System.AccessToken (Job access token). You can follow the documentation "Job access tokens" to check and assign System.AccessToken with the required permissions to access Wiki.