Home > database >  How add a specific variable into Azure Devops Libraries?
How add a specific variable into Azure Devops Libraries?

Time:11-30

In my pipeline (bash, ubuntu-latest) i want to add into already created library a variable (last git commit hash) is it possible ??

Documentation not telling too much about it

CodePudding user response:

You could use this API to update the variable group: enter image description here

Bash script:

curl --location --request PUT 'https://dev.azure.com/{OrgName}/{ProjName}t/_apis/distributedtask/variablegroups/{variablegroupsID}?api-version=7.0' \
--header 'Authorization: Basic {Base64PAT}=' \
--header 'Content-Type: application/json' \
--data-raw '{
    "variables": {
        "test": {
            "value": "$(Build.SourceVersion)"
        }
    },
    "id": 5,
    "type": "Vsts",
    "name": "1013",
    "description": "",
    "createdBy": {
        "displayName": "{displayName}",
        "id": "{id}",
        "uniqueName": "{uniqueName}"
    },
    "createdOn": "2022-10-13T07:41:40.3066667Z",
    "modifiedBy": {
        "displayName": "{displayName}",
        "id": "{id}",
        "uniqueName": "{uniqueName}"
    },
    "modifiedOn": "2022-10-13T07:41:40.3066667Z",
    "isShared": false,
    "variableGroupProjectReferences": [
        {
            "projectReference": {
                "id": "{Proj id}",
                "name": "{Proj Name}"
            },
            "name": "1013",
            "description": ""
        }
    ]
}'

Variable group sample:

enter image description here

Running the script via Azure Pipeline (bash, ubuntu-latest)

enter image description here

Result:

enter image description here

enter image description here

Update1

enter image description here

  • Related