You are currently viewing 2 Ways To Delete Azure Devops Project Wiki – REST API & CLI

2 Ways To Delete Azure Devops Project Wiki – REST API & CLI

In this article, I will show you how to delete the azure devops project wiki using the azure devops REST API and CLI.

RELATED ARTICLE :

When working with azure devops you can create and manage wiki-related resources using the web UI, CLI or REST API. We will usually work with the web UI to create wiki pages and add content. I always prefer to clone the wiki repository locally, commit and push the changes back to the repository.

The web UI contains different options to work with the pages and wiki but the delete/remove wiki is missing from the web UI. The only solution to completely remove the wiki is to delete the underlying git repository through azure devops CLI or REST API.

How To Delete Azure Devops Project Wiki Through CLI

To work with azure devops CLI, you need to install the extension on top of az cli. The following command will install the azure devops cli extension.

$  az extension add --name azure-devops

You can run the following command to check the list of installed extensions.

$ az extension list

[
  {
    "experimental": false,
    "extensionType": "whl",
    "name": "azure-devops",
    "path": "/home/dro/.azure/cliextensions/azure-devops",
    "preview": false,
    "version": "0.26.0"
  }
]

The following command can be used to access the help section.

$ az devops -h         # Top level
$ az devops wiki -h    # Wiki help

Set the organization and project where you want to delete the wiki.

$ az devops configure --defaults organization=https://dev.azure.com/{ORG-NAME} project={PROJECT-NAME}

Before running the azure devops related commands you should authenticate with azure either through az login or az devops login command.

$ az login   # AAD/MSA authentication
$ az devops login # PAT token based authentication

Get the project wiki metadata. The output of the below command is the list of JSON objects.

$ az devops wiki list 

The value in the id field is the repository ID. Using the repository ID I tried deleting the repo but again it throws the following error.

$ az devops wiki delete --wiki {id}
Are you sure you want to delete this wiki? (y/n): y
Wiki delete operation is not supported on wikis of type 'ProjectWiki'.

The only solution is to delete the underlying git repository mapped to the wiki. The az devops wiki list command will also give you the repositoryId for the underlying git repository.

Run the following azure devops repos command to remove the git repository.

$ az repos delete --id {repositoryId}
Are you sure you want to delete this repository? (y/n): y
Deleted repository {repositoryId}

To validate, you can navigate to the azure devops web UI wiki section. This time it will not prompt you with a new page the moment you click wiki.

How To Delete Azure Devops Project Wiki Through REST API.

Azure devops also supports REST API to work with services. Here I am using the CURL command as my client to work with REST API.

In the following command, I have created three variables from the bash shell and used it in the URI. You can also directly add the values in the URI. Pass the username and pat token with the -u flag. The current api version is 7.0. I suggest you check the current API version before running the command.

ORGINZATION="XXX"
PROJECT="YYY"
WIKI_NAME="ZZZ"
$ curl -u {UNAME}:{PAT-TOKEN} -X GET https://dev.azure.com/${ORGINAZTION}/${PROJECT}/_apis/wiki/wikis/${WIKI_NAME}.wiki?api-version=7.0

The above GET request will give a similar output to the az devops wiki list command but only for the given wiki name. Now run the following command to delete the wiki.

ORGINZATION="XXX"
PROJECT="YYY"
WIKI_NAME="ZZZ"
$ curl -u {UNAME}:{PAT-TOKEN} -X GET https://dev.azure.com/${ORGINAZTION}/${PROJECT}/_apis/wiki/wikis/${WIKI_NAME}.wiki?api-version=7.0

The delete operation will fail.

{
  "$id": "1",
  "innerException": null,
  "message": "Wiki delete operation is not supported on wikis of type 'ProjectWiki'.",
  "typeName": "Microsoft.TeamFoundation.Wiki.Server.WikiOperationNotSupportedException, Microsoft.TeamFoundation.Wiki.Server",
  "typeKey": "WikiOperationNotSupportedException",
  "errorCode": 0,
  "eventId": 3000
}

Finally, you can delete the underlying git repository. The GET request will give you the repositoryId.

ORGINZATION="XXX"
PROJECT="YYY"
REPO_ID="ZZZ"
$ curl -u {UNAME}:{PAT-TOKEN} -X GET https://dev.azure.com/${ORGINAZTION}/${PROJECT}/_apis/git/repositories/${REPO_ID}?api-version=7.0

Wrap Up

This article shows how to delete azure devops project wiki using the azure devops cli and REST API. Both approaches can be used in scripts to automatically clean up the repository or wiki. I hope the same feature is implemented soon in the azure web UI.

Leave a Reply

seventeen + 12 =