ARM模板部署Azure Container Apps Job时遇格式错误求助
Azure Container Apps Jobs部署ARM模板时Schema验证失败
部署ARM模板时收到以下错误提示:
警告:当前默认启用预览版扩展安装,未来版本将禁用。如需启用请使用'--allow-preview true',如需仅安装稳定版请使用'--allow-preview false'。 警告:已安装的'containerapp'扩展处于预览阶段。 错误:{"code": "InvalidTemplateDeployment", "message": "模板部署'containerapp'不符合验证规则,跟踪ID为'372358fe-1076-4b96-ae3c-b4b6abbd987e',详情请查看内部错误。"} 内部错误: {"code": "ValidationForResourceFailed", "message": "资源验证失败,查看'Error.Details[0]'获取更多信息。"} 内部错误: {"code": "ContainerAppsJobInvalidSchema", "message": "容器应用作业的请求体无效,不符合Container Apps Job Schema,如需更多信息请访问相关文档"}
我已查阅相关文档,但未发现我的模板与文档示例存在差异。使用AZ CLI命令部署时成功完成,对比CLI输出和ARM模板也未找到Schema差异,希望有人能指出模板中的问题。
以下是我的ARM模板:
{"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#","contentVersion": "1.0.0.0","parameters": {"environmentName": {"type": "string"},"location": {"type": "string"},"azpUrl": {"type": "securestring"},"azpToken": {"type": "securestring"},"azpPool": {"type": "string"},"azpPoolId": {"type": "int"},"registrayLoginServer": {"type": "string"},"registryUsername": {"type": "string"},"registryPassword": {"type": "securestring"},"image": {"type": "string"},"scaleOn": {"type": "int"},"minReplicas": {"type": "int"},"maxReplicas": {"type": "int"},"cpu": {"type": "int"},"memory": {"type": "string"},"containerAppName": {"type": "string"}},"resources": [{"apiVersion": "2023-05-01","type": "Microsoft.App/jobs","name": "[parameters('containerAppName')]","location": "[parameters('location')]","identity": {"type": "None"},"properties": {"environmentId": "[resourceId('Microsoft.App/managedEnvironments', parameters('environmentName'))]","configuration": {"triggerType": "Event","replicaTimeout": 1800,"replicaRetryLimit": 1,"secrets": [{"name": "azp-url","value": "[parameters('azpUrl')]"},{"name": "azp-token","value": "[parameters('azpToken')]"},{"name": "registry-password","value": "[parameters('registryPassword')]"}],"registries": [{"server": "[parameters('registrayLoginServer')]","username": "[parameters('registryUsername')]","passwordSecretRef": "registry-password"}],"eventTriggerConfig": {"parallelism": 1,"replicaCompletionCount": 1,"scale": {"minExecutions": "[parameters('minReplicas')]","maxExecutions": "[parameters('maxReplicas')]","pollingInterval": 10,"rules": [{"name": "azure-pipelines-scale-rule","auth": [{"secretRef": "azp-token","triggerParameter": "personalAccessToken"},{"secretRef": "azp-url","triggerParameter": "organizationURL"}],"type": "azure-pipelines","metadata": {"organizationURL": "[parameters('azpUrl')]","poolID": "[string(parameters('azpPoolId'))]","targetPipelinesQueueLength": "[string(parameters('scaleOn'))]"}}]}}},"template": {"containers": [{"image": "[parameters('image')]","imageType": "ContainerImage","name": "azure-pipelines-agent","env": [{"name": "AZP_URL","secretRef": "azp-url"},{"name": "AZP_TOKEN","secretRef": "azp-token"},{"name": "AZP_POOL","value": "[parameters('azpPool')]"},{"name": "AZP_POOLID","value": "[parameters('azpPoolId')]"}],"resources": {"cpu": "[parameters('cpu')]","memory": "[parameters('memory')]","ephemeralStorage": "50Gi"}}]}}}]}
执行ARM部署的脚本:
#!/bin/bash # 根据部署用途设置POOLID if [[ "${{ parameters.deploymentPurpose }}" == "DEV" ]]; then POOLID=17 elif [[ "${{ parameters.deploymentPurpose }}" == "Test" ]]; then POOLID=16 elif [[ "${{ parameters.deploymentPurpose }}" == "PROD" ]]; then POOLID=14 else POOLID=15 fi echo "POOLID已设置为 $POOLID" az extension add --name containerapp --yes az provider register --namespace Microsoft.App # 等待命名空间注册完成 while ! az provider show -n Microsoft.App --query "registrationState" -o tsv | grep -q "Registered"; do echo "等待Microsoft.App命名空间注册完成..." sleep 10 done AZP_URL="URL" AZP_TOKEN=$(pattoken) AZP_AGENT_NAME=${{ parameters.deploymentPurpose }} AZP_POOL=${{ parameters.deploymentPurpose }} REGISTRY_USERNAME=USERNAME REGISTRY_PASSWORD=$(acrpassword) REGISTRY_LOGIN_SERVER=ACRURL IMAGE=IMAGEURL CONTAINER_APP_NAME="devops-agent-$(echo "${{ parameters.deploymentPurpose }}" | tr '[:upper:]' '[:lower:]')" MIN_REPLICAS="${{ parameters.minReplicas }}" MAX_REPLICAS="${{ parameters.maxReplicas }}" CPU="${{ parameters.cpu }}" MEMORY="${{ parameters.memory }}Gi" SCALE_ON="${{ parameters.scalePoint }}" az deployment group create \ --resource-group $RESOURCE_GROUP \ --template-file "$(Build.SourcesDirectory)/src/DevOps/DevopsAgent/ContainerApp/containerapp.json" \ --parameters \ environmentName="$CONTAINERAPPS_ENVIRONMENT" \ location="$REGION" \ azpUrl="$AZP_URL" \ azpToken="$AZP_TOKEN" \ azpPool="$AZP_POOL" \ azpPoolId="$POOLID" \ registrayLoginServer=$REGISTRY_LOGIN_SERVER \ registryUsername=$REGISTRY_USERNAME \ registryPassword=$REGISTRY_PASSWORD \ image=$IMAGE \ scaleOn=$SCALE_ON \ minReplicas=$MIN_REPLICAS \ maxReplicas=$MAX_REPLICAS \ cpu=$CPU \ memory=$MEMORY \ containerAppName=$CONTAINER_APP_NAME
成功部署的AZ CLI命令:
az containerapp job create \ --name "$CONTAINER_APP_NAME" \ --resource-group "$RESOURCE_GROUP" \ --environment "$CONTAINERAPPS_ENVIRONMENT" \ --trigger-type "Event" \ --replica-timeout 1800 \ --replica-retry-limit 1 \ --registry-server "$REGISTRY_LOGIN_SERVER" \ --registry-username "$REGISTRY_USERNAME" \ --registry-password "$REGISTRY_PASSWORD" \ --image "$IMAGE" \ --cpu "$CPU" \ --memory "$MEMORY" \ --min-executions "$MIN_REPLICAS" \ --max-executions "$MAX_REPLICAS" \ --scale-rule-name "azure-pipelines-scale-rule" \ --scale-rule-type "azure-pipelines" \ --scale-rule-metadata "poolID=$POOLID" "targetPipelinesQueueLength=$SCALE_ON" \ --scale-rule-auth "personalAccessToken=secretref:azp-token" "organizationURL=secretref:azp-url" \ --secrets "azp-url=$AZP_URL" "azp-token=$AZP_TOKEN" \ --env-vars "AZP_URL=secretref:azp-url" "AZP_TOKEN=secretref:azp-token" "AZP_POOL=$AZP_POOL" "AZP_POOLID=$POOLID" "AZP_AGENT_NAME=$AZP_AGENT_NAME"
内容的提问来源于stack exchange,提问作者Funkel
相关产品推荐
相关产品推荐

