Azure DevOps 托管 ubuntu 代理问题更新应用程序网关
Azure DevOps hosted ubuntu agent issue updating Application Gateway
我使用 Terraform 部署了一些基础设施,包括应用程序网关。不幸的是,并非所有设置都可以 set/updated 使用 terraform。所以我有一个 shell 脚本来更新应用程序网关。
#!/bin/bash
SP_ID=
SP_SECRET=
TENANT_ID=
SUBSCRIPTION=
RG=
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 }')
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 }')
echo "Backend pool = ${BP}"
# Get the frontendip of the load balancer
LB=$(az network lb list --resource-group ${RG} | tail -n 1 | awk '{ print }')
LBFEIP=$(az network lb frontend-ip list --lb-name ${LB} --resource-group ${RG} | tail -n 1 | awk '{ print }')
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 }')
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 }')
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 代理部署脚本。
错误直接说明了问题。您的参数 "AG" 为空。您可以使用 CLI 命令获取参数 "AG":
az network application-gateway list -g nancyweb --query "[].name" -o tsv
或者你想要的输出格式 table:
az network application-gateway list -g nancyweb -o table | tail -n 1 | awk '{print }'
您可以获得有关 az network application-gateway list
的更多详细信息。但是如果你想得到具体的有一点你应该注意,因为list命令显示了所有的应用程序网关。
我使用 Terraform 部署了一些基础设施,包括应用程序网关。不幸的是,并非所有设置都可以 set/updated 使用 terraform。所以我有一个 shell 脚本来更新应用程序网关。
#!/bin/bash
SP_ID=
SP_SECRET=
TENANT_ID=
SUBSCRIPTION=
RG=
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 }')
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 }')
echo "Backend pool = ${BP}"
# Get the frontendip of the load balancer
LB=$(az network lb list --resource-group ${RG} | tail -n 1 | awk '{ print }')
LBFEIP=$(az network lb frontend-ip list --lb-name ${LB} --resource-group ${RG} | tail -n 1 | awk '{ print }')
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 }')
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 }')
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 代理部署脚本。
错误直接说明了问题。您的参数 "AG" 为空。您可以使用 CLI 命令获取参数 "AG":
az network application-gateway list -g nancyweb --query "[].name" -o tsv
或者你想要的输出格式 table:
az network application-gateway list -g nancyweb -o table | tail -n 1 | awk '{print }'
您可以获得有关 az network application-gateway list
的更多详细信息。但是如果你想得到具体的有一点你应该注意,因为list命令显示了所有的应用程序网关。