skip to Main Content

I am trying to execute REST API to link keyvault with variable group, when I execute below REST API command as it is executing but when I go to variable group the secrets are not saving and showing at the top

Value cannot be null. Parameter name: variableGroupParameters

Even when I want to update new secret, it is throwing the same error. Does anyone know the solution?

curl -X POST 
  -u :PAT_TOKEN 
  -H "Content-Type: application/json" 
  -d @kv_payload.json 
  "https://dev.azure.com/{org_name}/{project_name}/_apis/distributedtask/variablegroups?api-version=7.1-preview.1"

Payload

{
    "name": "variablegroupname",
    "type": "AzureKeyVault",
    "providerData": {
        "serviceEndpointId": "xxxxxxxxx",
        "vault": "keyvaultname"
    },
    "variables": {
        "storage-name": {
            "value": "null",
            "isSecret": true,
            "contentType": "",
            "enabled": true
        },
        "my-password": {
            "value": "null",
            "isSecret": true,
            "contentType": "",
            "enabled": true
        }
    },
    "description": "Keyvault secrets managed by automated script"
}

2

Answers


  1. I have also tried using the rest api, but also not work, and no error throw at my side.

      "providerData": {
        "vault": "wb-xxxx-test",
        "serviceEndpointId": "xxxxxx"
      }
    

    Although this providerData was added, the result was not linked successfully. The property providerData comes from that I manually create-get the keyvault linked variable group, should be correct.

    enter image description here


    My thoughts:

    keyvault link variable group operating on the ado UI is an interactive process. I think the logic behind this process may be more complicated and cannot be covered by a simple providerData property.

    Login or Signup to reply.
  2. You can link key vault to a variable group using below Rest API and request body.

    POST https://dev.azure.com/{organization}/_apis/distributedtask/variablegroups?api-version=7.2-preview.2
    

    Request body should be in below format-

    {
      "name": "MyVariableGroupForSecrets",
      "description": "variable group created for Key vault",
      "Type": "AzureKeyVault",
      "ProviderData": {
        "serviceEndpointId": "68d1****da6",
        "vault": "afreeenkvv"
      },
      "variables": {
        "test": {
          "value": "",
          "isSecret": true,
          "contentType": "",
          "enabled": true
        }
      },
      "variableGroupProjectReferences": [
        {
          "name": "MyVariableGroupForSecrets",
          "description": "variable group created for Key vault",
          "projectReference": {
            "id": "2cfd*****c5",
            "name": "{projectName}"
          }
        }
      ]
    }
    

    I am able to create the variable group.

    enter image description here

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search