Azure DevOps has a nice feature allowing teams to create a wiki within an Azure DevOps project. Functionality to publish code as a wiki was added later. The project wiki is likely backed with a git repo but that repo isn’t accessible. This post is about how to shift the project wiki to a code-backed wiki, allowing one to maintain the wiki as code allowing branches, pull requests and other git goodness.

There are essentially 3 steps:

  1. Create a repo from the existing wiki code
  2. Create a wiki from this code
  3. Remove the project wiki

Create a repo from the existing wiki code

  1. Select the button next to the wiki title and select Clone wiki

    image-20210803200321393

  2. In the pop-up select Generate Git credentials which will make a User Name and Password available. Keep these details open for future steps.

  3. In a new tab, open the same Azure DevOps project

  4. Select Repos-> Files

  5. Select the drop-down next to the Repo name and select Import repository image-20210803200914383

  6. Return to the previous tab and in the Clone repository popup, copy the HTTPS URL. This should be used as the Clone URL value.

  7. Once you’ve pasted this into the Import a Git repository dialog, you’ll also need to copy across the user name and password.

  8. The name can be changed but it’s recommended to shift to snake_case (e.g. myproject_wiki)

  9. The result should look like below image-20210803201525197

  10. Select Import and wait until the repo has been created.

Create a wiki from this code

  1. Return to the first tab and close the pop-up.

  2. Select the drop-down next to the wiki name and select Publish code as wiki image-20210803202111621

  3. Ensure the new wiki repo is selected as well as the main branch (likely wikiMaster)

  4. In folder fill in / and fill in a name image-20210803202306642

  5. Select Publish

  6. Congrats! You have a new wiki! 🎉 image-20210803202434196

  7. But! There’s now a duplicate wiki and the default will always be the project wiki. 😞 This is the reason for the next section.

Remove the project wiki

Unfortunately there is no way to remove the project wiki via the user interface. The removal needs to be done as an API call. And the API call needs to be done with authorization.

Get a Personal Access Token (PAT)

  1. Select the User Settings icon and then Personal access tokens image-20210803204808152

  2. Select to add a new token

  3. Give the token Full access but limit the Expiration to a single day (you can also remove the PAT after the project wiki has been removed) image-20210803205251489

  4. Keep the token in an accessible (and safe) place

Delete the Project Wiki with Postman

Note: If you prefer using curl check the next section.

  1. Install Postman

  2. Add a Collection and a Request

  3. Set the URL to

    https://dev.azure.com/{Organization}/{Project}/_apis/wiki/wikis?api-version=6.0
    
  4. Select the Authorization tab, select Type Basic Auth and set the Password to the PAT image-20210803211150456

  5. Send the request. The response should contain a list of two Wikis. Determine which one is the Project wiki and note down the ID of the wiki. image-20210803211347715

  6. Create a new request

  7. Change the method from GET to DELETE and set the URL to the following where repositoryId should be the ID of the wiki noted above.

    https://dev.azure.com/{Organization}/{Project}/_apis/git/repositories/{repositoryId}?api-version=6.0
    
  8. Select Authorization and ensure the Type and Password are the same as for the previous request.

  9. Select Send.

  10. Rerun the GET request and ensure that there is now only one wiki.

(Advanced) Delete the Project Wiki with curl

This assumes you have jq installed for formatting the JSON

  1. List the wikis of the project using the following curl command
curl -u :{Personal Access Token} --location --request GET 'https://dev.azure.com/{Organization}/{Project}/_apis/wiki/wikis?api-version=6.0' | jq
  1. Note down the ID of the wiki image-20210803212831262

  2. Delete the wiki repository using the following curl command

curl -u :{Personal Access Token} --location --request DELETE 'https://dev.azure.com/{Organization}/{Project}/_apis/git/repositories/{Wiki ID}?api-version=6.0'
  1. Rerun the GET request and ensure that there is only one wiki.