从另一个变量组更新 Azure DevOps 变量组的多个值

时间:2021-06-15 12:04:08

标签: azure-devops azure-cli

我有一个要求如下:

变量组A,有7组键=值对 变量组 B,有 7 组键值对。

在这两种情况下,键是相同的,只是值不同。

我向用户询问,注入变量组B的值,用户提供给我变量组A的名称。

执行此类更新的代码片段如下:

export reference_env="Variable Group A"
export target_env="Variable Group B"

values=(addressSearchBaseUrl addressSearchSubscriptionKey cacheUrl calendarApiUrl checkoutBffApiUrl cpCode)

groupId=$(az pipelines variable-group list --group-name "${reference_env}" | jq -r '. [].id')

#grab groupid for further checks later on.

az_create_options=()

for ptr in "${values[@]}"
do
    result=$(
      az pipelines variable-group list --group-name "${Variable Group ${reference_env}" | jq '.[0].variables.'${ptr}'.value'
    )
    printf "%s\t%s\t%d\n" "$ptr" "$result" $?

if [[ "$ptr" = "calendarApiUrl"  ]]
then
   echo "INF: Updating $ptr with new value"
   result="https://noname-api.platform.test.com.au/marketing/calendar/v1/AvailableDates/market1/"
   insertString=";rev=${target_env}"
   lookingfor="v1"
   result=$(echo $result| sed s/"${lookingfor}"/"${insertString}"/g)
   echo $result
fi


az_create_options+=("$ptr"="$result" )
done

declare -p az_create_options

az pipelines variable-group variable update --group-id 1202 --name "${target_env}" "${az_create_options[@]}"

但是,当我运行它时,出现如下错误: 注意:我根据 IP 屏蔽了这些值,但错误是一样的。

ERROR: unrecognized arguments: addressSearchBaseUrl="https://xxxxxxxxxx" addressSearchSubscriptionKey="yyyyyyyyyyyyyyy" cacheUrl="qqqqqqqqqqqqq" calendarApiUrl=tttttttttttttttt checkoutBffApiUrl="sssssssssssssssss" cpCode="333333"

有人可以指导我吗?

1 个答案:

答案 0 :(得分:1)

您错误地使用了更新命令:

az pipelines variable-group variable update --group-id
                                            --name
                                            [--detect {false, true}]
                                            [--new-name]
                                            [--org]
                                            [--project]
                                            [--prompt-value {false, true}]
                                            [--secret {false, true}]
                                            [--subscription]
                                            [--value]

name 是一个可变名称。所以如果你想更新每个变量你需要一个一个的更新。