I am using these commands to create a test Azure Wiki page.
#Azure DevOps Login < Works OK
echo '$env:ado_documentation_api_key' | az devops login --org https://dev.azure.com/***
#Create Code Wiki < Works OK
$Wiki_id = az devops wiki create --name test --type codewiki --version master --repository Azure.Agents --mapped-path /Documentation --query id -o tsv
#Create Wiki Page < Doesn't work
az devops wiki page create --path 'Documentation' --wiki $Wiki_id --file-path ./wiki.md --encoding utf-8
Expected behaviour:
To upload a new wiki page in Azure DevOps.
Actual behaviour:
The versionType should be 'branch' and version cannot not be null
Parameter name: versionDescriptor
Any assistance to resolve this issue, would be appreciated.
Reproduce the same issue when use the same Rest API to create Wiki Page.
The cause of the issue is from the Azure DevOps CLI extension itself.
When you add the --debug
argument in Azure DevOps CLI, you will see that the az devops wiki page create command is using the Rest API version 5.0.
Refer to this doc about Pages - Create Or Update Version 5.0 It doesn't support the parameters: versionType
.
This parameter is available after Rest API version 5.1.
The root cause of the issue is that Azure DevOps CLI requires versionType parameter, but Azure DevOps CLI is using old version of Rest API which doesn't support the version type argument.
This is a known issue with Azure DevOps CLI creating wiki pages. Refer to this Feedback ticket: Create wiki page using CLI extension fails with error "The versionType should be 'branch' and version cannot not be null"
For a workaround, you can use Rest API to create the wiki page: Pages - Create Or Update
Here is a PowerShell example:
$content = [IO.File]::ReadAllText("wiki\file.md")
$data= @{content=$content;} | ConvertTo-Json;
$OrganizationName = "organizationName"
$ProjectName = "ProjectName"
$WikiName = "WikiName"
$WikiPath = "MainPage"
$PAT="PAT Token"
$uri = "https://dev.azure.com/$OrganizationName/$ProjectName/_apis/wiki/wikis/$WikiName/pages?path=$WikiPath/$WikiSubPagePath&api-version=6.0"
$Header = @{
'Authorization' = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($PAT)"))
}
$params = @{
Uri = $uri;
Headers = $Header;
Method = 'Put';
ContentType = "application/json";
body = $data;
}
Invoke-RestMethod @params