Azure DevOps托管的ubuntu代理发布了更新应用程序网关的问题

时间:2018-11-12 16:11:46

标签: azure azure-devops terraform azure-cli

我使用Terraform部署了一些基础设施,包括一个应用程序网关。不幸的是,并非所有设置都可以使用terraform进行设置/更新。所以我有一个外壳脚本来更新应用程序网关。

#!/bin/bash
SP_ID=${1}
SP_SECRET=${2}
TENANT_ID=${3}
SUBSCRIPTION=${4}
RG=${5}

az login --service-principal -u ${SP_ID} -p ${SP_SECRET} -t ${TENANT_ID}
az account set --subscription ${SUBSCRIPTION}
az account list -o table

# Get the name of the AG
echo "RG = ${RG}"
AG=$(az network application-gateway list --resource-group ${RG} | tail -n 1 | awk '{ print $2 }')
echo "AG = ${AG}"

# Get the AG backend pool name
BP=$(az network application-gateway address-pool list --resource-group ${RG} --gateway-name ${AG} | tail -n 1 | awk '{ print $1 }')
echo "Backend pool = ${BP}"

# Get the frontendip of the load balancer
LB=$(az network lb list --resource-group ${RG} | tail -n 1 | awk '{ print $2         }')
LBFEIP=$(az network lb frontend-ip list --lb-name ${LB} --resource-group    ${RG} | tail -n 1 | awk '{ print $2 }')
echo "Load balancer = ${LB}"
echo "Frontend ip LB =  ${LBFEIP}"

# Update the backend pool of the AG with the frontend ip of the loadbalancer
echo "Updating Backend address pool of AG ${AG}"
az network application-gateway address-pool update --gateway-name $AG --resource-group $RG --name $BP --servers ${LBFEIP}

# Update http settings
echo "Updating HTTP settings of AG ${AG}"
AG_HTS=$(az network application-gateway http-settings list --resource-group     ${RG} --gateway-name ${AG} | tail -n 1 | awk '{ print $2 }')
az network application-gateway http-settings update --resource-group ${RG} --gateway-name ${AG} --name ${AG_HTS} --host-name-from-backend-pool true

# Update health probe
echo "Updating Health probe of AG ${AG}"
AG_HP=$(az network application-gateway probe list --resource-group ${RG} --gateway-name ${AG} | tail -n 1 | awk '{ print $4 }')
az network application-gateway probe update --resource-group ${RG} --gateway-name ${AG} --name ${AG_HP} --host '' --host-name-from-http-settings true

此脚本可以从我的笔记本电脑本地运行良好,但是通过azure devops发布管道,我得到了错误:

ERROR: az network application-gateway address-pool list: error: argument --gateway-name: expected one argument

以某种方式无法在脚本通过发布管道运行时获取应用程序网关名称。 同样,在本地运行此脚本时,它可以正常运行。有人知道我在这里可能会错过的内容或可以尝试吗?

我在WSL Ubuntu上创建了脚本,并使用ubuntu托管代理发布了工件,还使用了托管ubuntu代理部署了脚本。

1 个答案:

答案 0 :(得分:1)

该错误直接表明问题所在。您的参数“ AG”为空。您可以使用CLI命令获取参数“ AG”:

az network application-gateway list -g nancyweb --query "[].name" -o tsv

或根据需要使用输出格式表:

az network application-gateway list -g nancyweb -o table | tail -n 1 | awk '{print $3}'

您可以获得有关az network application-gateway list的更多详细信息。但是,如果要获取特定的网关,则需要注意一点,因为list命令显示了所有应用程序网关。