如何修复 bash 语法错误并使用 Jenkins/azure cli 来自动化 VM start/stop

How to fix bash syntax error and use Jenkins/azure cli to automate VM start/stop

我在 Jenkins 的工作中遇到了问题 运行。我有 $OPTION (start/stop) 的参数,但出现错误:syntax error near unexpected token 'fi'

az resource list --tag Restart=${TAG_RESTART} --query "[].{Name:name,RG:resourceGroup}" -o table  
vm_ids=''

if [[ "${OPTION}" == 'start' ]]; then

    vm_ids=($(az resource list --tag Restart=${TAG_RESTART} --query "[?type=='Microsoft.Compute/virtualMachines'].id" -o tsv))
    for i in "${vm_ids[@]}"

do
    az vm start --ids $i
    az vm show  -d --ids $(az resource list --tag Restart=${TAG_RESTART} --query "[?type=='Microsoft.Compute/virtualMachines'].id"|jq -r ".[]") --query '{Name:name,RG:resourceGroup,Status:powerState}' -o table > START_VMsInfo_$(date +%F_%R).txt
    echo ""${vm_ids[@]}" has started successfully"
fi

if [[ "${OPTION}" == 'stop' ]]; then    

    vm_ids=($(az resource list --tag Restart=${TAG_RESTART} --query "[?type=='Microsoft.Compute/virtualMachines'].id" -o tsv))
    for i in "${vm_ids[@]}"

do
    az vm deallocate --ids $i
    az vm show  -d --ids $(az resource list --tag Restart=${TAG_RESTART} --query "[?type=='Microsoft.Compute/virtualMachines'].id"|jq -r ".[]") --query '{Name:name,RG:resourceGroup,Status:powerState}' -o table > STOP_VMsInfo_$(date +%F_%R).txt
    echo ""${vm_ids[@]}" has deallocated successfully"
fi
if [[ "${OPTION}" == 'start' ]]; 
then
    vm_ids=($(az resource list --tag Restart=${TAG_RESTART} --query "[?type=='Microsoft.Compute/virtualMachines'].id" -o tsv))
        for i in "${vm_ids[@]}"    
do
   echo "doing something"
done
fi