Cannot update variable group with Azure DevOps API _apis/distributedtask/variablegroups

Viewed 30

I am trying to update a variable group from an Azure DevOps Pipeline. This is the API documentation from Microsoft. I am calling this API via Postman with HTTP PUT and a Header Authorization Basic {PAT}. The URL is https://dev.azure.com/{organization}/_apis/distributedtask/variablegroups/{groupId}?api-version=6.0-preview.2 Regardless of the JSON body it always returns:

{
  "$id": "1",
  "innerException": null,
  "message": "Project information name is not valid for variable group.",
  "typeName": "System.ArgumentException, mscorlib",
  "typeKey": "ArgumentException",
  "errorCode": 0,
  "eventId": 0
 }

Sample JSON Bodies:

Test 1

{
  "type": "Vsts",
  "name":"JobStatus"
}

Test 2

{
  "variables": {
      "rest-var1": {
          "isSecret": false,
          "value": "rest-var-value-1"
      },
      "rest-var2": {
          "isSecret": false,
          "value": "rest-var-value-2"
      },
      "rest-var3": {
          "isSecret": false,
          "value": "rest-var-value-3"
      }
  },
  "name":"JobStatus"
}

If I call this same API with HTTP GET it returns all of the details of the group. This was reported as a bug to Microsoft but the page didn't provide any details as to the solution.

1 Answers

"Project information name is not valid for variable group."

The error means that you need to define the project information in the Request Body.

Here is the Rest API example:

Rest API url:

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

Request Body:

{
    "name":"{variablegroupname}",

    "type":"Vsts",
    "variables":{
        "var1":{
            "isSecret":false,
            "value": "xx"
            },
        "var2":{
            "isSecret":false,
            "value": "xx"
            },
        "var3":{
            "isSecret":false,
            "value": "xx"
            }
        },
        "variableGroupProjectReferences":[
            {
                "name":"{variablegroupname}",
                "projectReference":
                    {
                        "id":"{projectid}"  
                    }
            }
        ]
}
Related