gianfrancopintus
gianfrancopintus

Reputation: 43

Share azure devops variables across projects

I am trying to share linked variables across projects. I read that is was not possible but I found this API endpoint that may do the trick. https://learn.microsoft.com/en-us/rest/api/azure/devops/distributedtask/variablegroups/share-variable-group?view=azure-devops-rest-6.0

When I call this API: PATCH https://dev.azure.com/{organization}/_apis/distributedtask/variablegroups?variableGroupId={variableGroupId}&api-version=6.0-preview.2

with this Body:

{
"variableGroupProjectReferences":[
    {
        "description":"test1",
        "name":"test1",
        "projectReference":{
            "id":"50f7c113-de21-4e19-b910-b37ebffa984f",
            "name":"Customer Services"
        }
    }]
}

I get this response:

{
    "$id": "1",
    "innerException": null,
    "message": "Value cannot be null.\r\nParameter name: variableGroupProjectReferences",
    "typeName": "System.ArgumentNullException, mscorlib",
    "typeKey": "ArgumentNullException",
    "errorCode": 0,
    "eventId": 0
}

Upvotes: 1

Views: 710

Answers (1)

Kevin Lu-MSFT
Kevin Lu-MSFT

Reputation: 35424

Value cannot be null.\r\nParameter name: variableGroupProjectReferences

The request body seems to have issue.

You can refer to the following sample:

[
    {

    "variableGroupProjectReferences": 
    {
        "projectReference": {
        "id": "ProjectID",
        "name": "ProjectName"
        },
        "name": "variablegroupname",
        "description": ""
        }
 
   }
]

But it will show the error: Sharing of variable group is not allowed.

The cause of this issue is that the variable group property: "isShared": false

You can get the variable group property with the Rest API: Variablegroups - Get

But currently it seems that we cannot change this property. So we couldn't share the variable group.

Refer to this feedback ticket: VariableGroup cannot be shared via REST API.

I suggest that you can report the issue to Developer Community.

Upvotes: 1

Related Questions