Delete the project WIKI in Azure DevOps with Azure CLI

Martin Tirion
3 min readMar 31, 2022

--

Recently I started working on a project using Azure DevOps. The project and repository were already setup some time ago. To properly set up documentation and the WIKI, I wanted to use WIKI as Code pointing to the /docs folder in our repo. That’s easy to do. But I still had the project WIKI that someone started and wanted to get rid of it. But … how?

I first start to search the UI for an option, but found none. So your next best friend is … Google/Bing search 🤓 I found this post: Delete default project Wiki in Azure DevOps — sanderh.dev (by Sander Holvoet) which helped me to get the idea. But this post uses postman and I wanted to do this with Azure CLI. In this post I’ll share those (easy) steps (once you know it).

Connect to Azure with Azure CLI

To get you started, open a PowerShell Command window and login to Azure using:

az login

Select the correct subscription

Now you’re connected to Azure and can see your subscription(s). If you’re connected to multiple subscriptions, make sure the correct one is set where your Azure DevOps environment lives. To show your current selected subscription:

az account show

To show all the subscriptions you have access to through your account:

az account list

And to select another subscription, use:

az account set --subscription <subscription id>

Use the Azure DevOps CLI extension

For the rest of the commands we’ll be using the Azure DevOps CLI extension. You can install that like this:

az extension add --name azure-devops

List the WIKI’s in your project

Now you can see all the WIKI’s in your Azure DevOps project with this command:

az devops wiki list

You probably get an error using this command, where it tells you to specify the organization and project. You can set that as global setting, but in case you didn’t you’ll have to specify this through parameters. Something like this:

az devops wiki list --organization https://dev.azure.com/<your organization> --project "<project name>"

In my case it returned 2 entries: one of type codeWiki and one of type projectWiki. The projectWiki type is the default one where you can edit in the UI. I want to remove that one. So I tried:

az devops wiki delete -wiki <wiki id> --organization <organization url> --project "<project name>"

But when you issue that command for a projectWiki you get this error:

Wiki delete operation is not supported on wikis of type ‘ProjectWiki’.

Sander’s post helped me out here. If you can’t delete the WIKI, delete the repository that’s backing that WIKI. When you get the details of the project WIKI you will see something like this (redacted JSON):

{
"id": "bb17a000-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"mappedPath": "/",
"name": "wiki.3991e018-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"projectId": "3991e018-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"properties": null,
"remoteUrl": "https://dev.azure.com/...",
"repositoryId": "bb17a000-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"type": "projectWiki",
"url": "https://dev.azure.com/...",
"versions": [{
"version": "wikiMaster",
"versionOptions": null,
"versionType": null
}]
}

You see that there is repositoryId attached to the project WIKI. This is NOT the repo that the rest of your code is in. This is a separate one just for the project WIKI. If you want to make sure, compare the repositoryId of the other WIKI’s or repos. The trick is to remove that one, and the project WIKI is gone.

NOTE: really make sure you want to delete this repo. When it’s gone, it’s gone!

To remove that repo, use this command:

az repos delete --id <repositoryId> --organization <organization url> --project "<project name>"

Now the project WIKI doesn’t exist anymore, as it is automatically deleted because the backing repository is deleted. Exactly what I was aiming for.

Hope this helps if you have the same issue 😊

--

--

Martin Tirion
Martin Tirion

Written by Martin Tirion

Senior Software Engineer at Microsoft working on Azure Services and Spatial Computing for enterprise customers around the world.

No responses yet