Vnet创建任务如果运行一次,则跳过该任务

时间:2019-12-26 05:38:36

标签: azure azure-devops azure-pipelines

我正在为AKS构建ci / cd管道。第一个任务集是“ Azure资源组部署”,用于为AKS创建vnet / subnet。
由于vnet和子网已经存在,因此下一次将跳过此任务。第二次以后出现以下错误-

BadRequest: { "error": { "code": "InUseSubnetCannotBeDeleted", "message": "Subnet AKSSubnet is in use by /subscriptions/***************************************/resourceGroups/MC_**************-CLUSTER_eastus/providers/Microsoft.Network/networkInterfaces/aks-agentpool-
########-nic-0/ipConfigurations/ipconfig1 and cannot be deleted. In order to delete the subnet, delete all the resources within the subnet. See aka.ms/deletesubnet.", "details": [] } }  
Error:  Task failed while creating or updating the template deployment. 

看起来任务正在尝试删除子网,而不是跳过子网。分辨率是多少?

它使用以下手臂模板:azuredeploy.json

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "vnetName": {
      "type": "string",
      "defaultValue": "GEN-VNET-NAME",
      "metadata": {
        "description": "Name of the virtual Network"
      }
    },
    "vnetAddressPrefix": {
      "type": "string",
      "defaultValue": "10.10.0.0/16",
      "metadata": {
        "description": "Address prefix"
      }
    },
    "subnetPrefix": {
      "type": "string",
      "defaultValue": "10.10.0.0/24",
      "metadata": {
        "description": "Subnet Prefix"
      }
    },
    "subnetName": {
      "type": "string",
      "defaultValue": "Subnet",
      "metadata": {
        "description": "GEN-SUBNET-NAME"
      }
    }
  },
  "variables": {},
  "resources": [
    {
      "apiVersion": "2018-06-01",
      "type": "Microsoft.Network/virtualNetworks",
      "name": "[parameters('vnetName')]",
      "location": "[resourceGroup().location]",
      "properties": {
        "addressSpace": {
          "addressPrefixes": [
            "[parameters('vnetAddressPrefix')]"
          ]
        }
      },
      "resources": [
        {
          "apiVersion": "2018-06-01",
          "type": "subnets",
          "location": "[resourceGroup().location]",
          "name": "[parameters('subnetName')]",
          "dependsOn": [
            "[parameters('vnetName')]"
          ],
          "properties": {
            "addressPrefix": "[parameters('subnetPrefix')]"
          }
        }
      ]
    }
  ],
  "outputs": {
    "vnetName": {
      "type": "string",
      "value": "[parameters('vnetName')]"
    },
    "subnetName": {
      "type": "string",
      "value": "[parameters('subnetName')]"
    }
  }
}

azuredeploy.parameters.json

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "vnetName": {
      "value": "###########"
    },
    "vnetAddressPrefix": {
      "value": "10.10.0.0/16"
    },
    "subnetPrefix": {
      "value": "10.10.0.0/24"
    },
    "subnetName": {
      "value": "######"
    }
  }
}

1 个答案:

答案 0 :(得分:0)

这是怎么回事-您的模板是以这种方式编写的代码:

vnet resources
  empty subnets property
subnet resource(s)
bla-bla-bla

,由于您创作模板的方式,这里正在发生的事情试图将vnet强制为0个子网。您有2个选择:

  1. 如果内部版本号大于1(或在构建时手动指定是否跳过它),则对vnet资源定义施加条件并向其传递参数。
  2. 修改模板,使其看起来像这样:
vnet resource
  subnets property populated with subnets
bla-bla-bla

本质上,这与Azure Devops无关。