azure-devopsazure-pipelinesazure-cli

Cannot update Azure DevOps wiki from pipeline


I am attempting to update our Azure DevOps wiki from an Azure DevOps pipeline in the same project.

Each time, I receive the following error: Repository associated with wiki ID 'acf82e19-xxxx-xxxx-xxxx-xxxxxxxxxxxx' does not exist or you do not have permissions for the operation you are attempting.

Note that the wiki show command succeeds, but wiki page create fails. Running the same command locally (following az login) does work, so this is about the permissions available to the DevOps pipeline.

In Wiki security, I have allowed Contribute access to the "[Project name] Build Service ([Org name])" user.

I have also added the WikiGit repository as a resource in my yaml (see below), as recommended here.

Additionally, I have tried using Invoke-RestMethod to call the API via PowerShell, as per this question, but I receive the same error response.

My yaml code is as follows:

trigger: none

resources:
  repositories:
    - repository: WikiGit
      type: git
      name: [Project name].wiki

steps:
  - script: |
      az devops wiki show --wiki "[Project name].wiki" --verbose
      az devops wiki page create --path NewPage --wiki "[Project name].wiki" --comment "added a new page" --content "# New Wiki Page Created!" --verbose
    env:
      AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)

Here is the full output:

INFO: Detect: Url discovery took 0:00:00.002002
INFO: received PAT from environment variable
INFO: Creating connection with personal access token.
INFO: Command ran in 0.660 seconds (init: 0.130, invoke: 0.530)
{
  "id": "acf82e19-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "mappedPath": "/",
  "name": "[Project name].wiki",
  "projectId": "5feec93a-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "properties": null,
  "remoteUrl": "https://dev.azure.com/[Org name]/5feec93a-xxxx-xxxx-xxxx-xxxxxxxxxxxx/_wiki/wikis/acf82e19-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "repositoryId": "acf82e19-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "type": "projectWiki",
  "url": "https://dev.azure.com/[Org name]/5feec93a-xxxx-xxxx-xxxx-xxxxxxxxxxxx/_apis/wiki/wikis/acf82e19-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "versions": [
    {
      "version": "wikiMaster",
      "versionOptions": null,
      "versionType": null
    }
  ]
}
INFO: Detect: Url discovery took 0:00:00.001961
INFO: received PAT from environment variable
INFO: Creating connection with personal access token.
ERROR: Repository associated with wiki ID 'acf82e19-xxxx-xxxx-xxxx-xxxxxxxxxxxx' does not exist or you do not have permissions for the operation you are attempting.
INFO: Command ran in 0.511 seconds (init: 0.131, invoke: 0.380)


Solution

  • The solution, it seems, is to add uses:

    trigger: none
    
    resources:
      repositories:
        - repository: WikiGit
          type: git
          name: [Project name].wiki
    
    jobs:
      - job:
        uses: # This will not checkout the repo to the agent, but will add the repo to the agent PAT
          repositories:
            - WikiGit
        steps:
          - script: |
              az devops wiki show --wiki "[Project name].wiki" --verbose
              az devops wiki page create --path NewPage --wiki "[Project name].wiki" --comment "added a new page" --content "# New Wiki Page Created!" --verbose
            env:
              AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)
    

    Thanks to this Visual Sudio Developer Community answer.