Search code examples
azure-devopsmarkdownazure-pipelineswikirelease-notes

Publishing release notes to TFS/VSTS Wiki during Release


My mission is to generate and publish release notes on WIKI automatically when ever the release triggered, for this I am following this Blog, its very handy blog, but my bad luck still not able to create wiki page with release template. (using both Azure DevOps and TFS)

enter image description here

Template:

**Build Number**  : $($build.buildnumber)    
**Build started** : $("{0:dd/MM/yy HH:mm:ss}" -f [datetime]$build.startTime)     
**Source Branch** : $($build.sourceBranch)  
###Associated work items  
@@WILOOP@@  
* #$($widetail.id)
@@WILOOP@@  
###Associated change sets/commits  
@@CSLOOP@@  
* **ID $($csdetail.changesetid)$($csdetail.commitid)** 
  >$($csdetail.comment)    
@@CSLOOP@@

PowerShell Script

$content = [IO.File]::ReadAllText("$(System.DefaultWorkingDirectory)\releasenotes.md")
$data = @{content=$content;} | ConvertTo-Json;
$params = @{uri = '$(WikiPath)';
  Method = 'PUT';
  Headers = @{Authorization = "Bearer $(System.AccessToken)" };
  ContentType = "application/json";
  Body = $data;
}
Invoke-WebRequest @params

Please guide me what I am doing wrong


Solution

  • After testing, we find that the PowerShell script in your mentioned blog uses this Rest API: Pages - Create Or Update, thus the wikipath is the requested url like below format:

    https://dev.azure.com/{organization}/{project}/_apis/wiki/wikis/{wikiIdentifier}/pages?path={path}&api-version=6.0

    For example, we create a project wiki named scrum-test.wiki, and want to create a new wiki page named Release notes, the url would like below

    https://dev.azure.com/{organization}/{project}/_apis/wiki/wikis/scrum-test.wiki/pages?path=Release notes&api-version=6.0

    If we now want to create a child wiki page named 0.1.0 under Release notes page, the url would be like below

    https://dev.azure.com/{organization}/{project}/_apis/wiki/wikis/scrum-test.wiki/pages?path=Release notes/0.1.0&api-version=6.0

    In addition, using AccessToken we always get error which says that "The wiki page operation failed with message : User does not have write permissions for this wiki." even we grant full wiki permissions for identity: {project name} Build Service ({organization name}), so we use PAT authentication with full access and it works fine with below PowerShell script.

    $content = [IO.File]::ReadAllText("$(System.DefaultWorkingDirectory)\releasenotes.md")
    $data = @{content=$content;} | ConvertTo-Json;
    
    $connectionToken="PAT here"
    
    $base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($connectionToken)"))
    
    $params = @{uri = '$(WikiPath)';
      Method = 'PUT';
      Headers = @{Authorization = "Basic $base64AuthInfo" };
      ContentType = "application/json";
      Body = $data;
    }
    Invoke-WebRequest @params