Search code examples
azureazure-devopsazure-pipelinesazure-pipelines-yaml

Azure devops variables are not updating


I am trying to update the devops pipeline library variables through azure devops task via yaml. This is the code I have

- script: |
    echo "Updating variable group..."
    echo $(System.AccessToken) | az devops login --organization https://dev.azure.com/<org_name>
    echo "Logged in..."
    az devops project list -o jsonc
    az devops configure --defaults organization=https://dev.azure.com/<org_name>
    echo "Configured..."
    az pipelines variable-group list --top 6 --query-order Asc --output table --project "Test"
    echo "Listing success..."
    az pipelines variable-group variable update -p "Test" --group-id 2 --name version --value Test --output table
    echo "Update success..."

However,this code stops executing after az devops configure --defaults organization=https://dev.azure.com/<org_name> and the other echo commands are not visible in the log and none of the variables are getting updated. And worth to mention no errors as well. But if I run the same commands from my laptop terminal it works as expected. I am not sure what's wrong with this command. Any assist will be greatly appreciated.


Solution

  • Try something like this:

    - bash: |
        az pipelines variable-group variable update \
          --group-id <VARIABLE_GROUP_ID> \
          --name <VARIABLE_NAME> \
          --value <VARIABLE_VALUE> \
          --organization 'https://dev.azure.com/<MY_ORG>/' \
          --project '<MY_PROJECT>' \
          --output table
      displayName: 'Update variable'
      env:
        AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)
    

    Notes:

    • If the az devops configure --defaults organization=... doesn't work for some reason, you can use the --organization or --org directly in the commands you want to execute
    • Please ensure $(System.AccessToken) has enough permissions to list and update variable groups
    • Azure DevOps CLI authentication can be done using environment variable AZURE_DEVOPS_EXT_PAT - see Sign in with a personal access token (PAT).