gpt4 book ai didi

json - CI 管道失败,即使它正在做它应该做的事情

转载 作者:行者123 更新时间:2023-12-03 02:30:58 25 4
gpt4 key购买 nike

首先我要说的是,我刚刚开始使用 Azure,绝不是专业人士,并且一直在遵循各种指南。所以,我正在关注this文章通过部署this在我自己的 Azure DevOps 订阅中存储库,在更改资源组、订阅和函数名称后,我构建并运行 CI 管道,然后在“部署 Azure 资源”处我会得到 this即使在管道退出后,资源按照预期的方式创建,我也注意到如果我第二次重新运行相同的管道,它会完美地工作,这令人困惑。这是我修改后的 YAML 模板

name: DeployAzureFunction
variables:
FunctionAppName: 'test'
AzureConnection: 'DevOps-Test'
ResourcegGroupName: 'test'

trigger:
branches:
include:
- '*' # must quote since "*" is a YAML reserved character; we want a string



stages:

- stage: Build
jobs:
- job: Test_FA
pool:
vmImage: windows-2019
steps:
- task: AzureResourceGroupDeployment@2
displayName: 'Test ARM Deployment'
inputs:
azureSubscription: $(AzureConnection)
resourceGroupName: $(ResourcegGroupName)
location: 'East US 2'
csmFile: Deployment/azuredeploy.json
deploymentMode: Validation
- powershell: |
Install-PackageProvider -Name NuGet -Force -Scope CurrentUser
Install-Module -Name Pester -Force -Scope CurrentUser -SkipPublisherCheck
Install-Module -Name PSScriptAnalyzer -Force -Scope CurrentUser
displayName: 'Install Pester and import module'

- job: Build_FA
pool:
vmImage: windows-2019
steps:
- task: ArchiveFiles@2
displayName: 'Archive FunctionApp'
inputs:
rootFolderOrFile: FunctionApp
includeRootFolder: false
archiveFile: '$(System.DefaultWorkingDirectory)/zip/FunctionApp.zip'
- task: PublishPipelineArtifact@0
inputs:
artifactName: 'zip'
targetPath: '$(System.DefaultWorkingDirectory)/zip'

- stage: Deploy
jobs:
- job: Deploy_ARM
pool:
vmImage: windows-2019
steps:
- task: AzureResourceGroupDeployment@2
displayName: 'Deploy Azure Resources'
continueOnError: true
inputs:
azureSubscription: $(AzureConnection)
resourceGroupName: $(ResourcegGroupName)
location: 'East US 2'
csmFile: Deployment/azuredeploy.json
csmParametersFile: Deployment/azuredeploy.parameters.json
overrideParameters: '-functionAppName $(FunctionAppName)'
deploymentMode: Incremental
deploymentOutputs: DeploymentOutput

这是未修改的 azuredeploy.json,我认为它导致了问题,但不确定原因

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"functionAppName": {
"type": "string",
"defaultValue": "[uniqueString(resourceGroup().id)]",
"metadata": {
"description": "Specify the name of the function application"
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Specify the location for the function application resources"
}
}
},
"variables": {
"hostingPlanName": "[parameters('functionAppName')]",
"storageacccount": "[toLower(parameters('functionAppName'))]",
"storageAccountName": "[concat('storage', variables('storageacccount'))]"
},
"resources": [
{
"apiVersion": "2017-06-01",
"type": "Microsoft.Storage/storageAccounts",
"name": "[variables('storageAccountName')]",
"location": "[parameters('location')]",
"kind": "Storage",
"sku": {
"name": "Standard_LRS"
}
},
{
"type": "Microsoft.Web/serverfarms",
"apiVersion": "2018-11-01",
"name": "[variables('hostingPlanName')]",
"location": "[parameters('location')]",
"sku": {
"name": "Y1",
"tier": "Dynamic",
"size": "Y1",
"family": "Y",
"capacity": 0
},
"properties": {
"name": "[variables('hostingPlanName')]"
}
},
{
"name": "[parameters('functionAppName')]",
"type": "Microsoft.Web/sites",
"apiVersion": "2018-02-01",
"location": "[parameters('location')]",
"kind": "functionapp",
"dependsOn": [
"[resourceId('Microsoft.Web/serverfarms/', variables('hostingPlanName'))]",
"[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]",
"[resourceId('microsoft.insights/components/', parameters('functionAppName'))]"
],
"identity": {
"type": "SystemAssigned"
},
"properties": {
"siteConfig": {
"appSettings": [
{
"name": "FUNCTIONS_WORKER_RUNTIME",
"value": "powershell"
},
{
"name": "AzureWebJobsStorage",
"value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';AccountKey=', listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')), '2017-06-01').keys[0].value)]"
},
{
"name": "FUNCTIONS_EXTENSION_VERSION",
"value": "~2"
},
{
"name": "APPINSIGHTS_INSTRUMENTATIONKEY",
"value": "[reference(resourceId('microsoft.insights/components/', parameters('functionAppName')), '2018-05-01-preview').InstrumentationKey]"
},
{
"name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING",
"value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';AccountKey=', listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')),'2017-06-01').keys[0].value)]"
},
{
"name": "WEBSITE_CONTENTSHARE",
"value": "[toLower(parameters('functionAppName'))]"
}
]
},
"name": "[parameters('functionAppName')]",
"clientAffinityEnabled": false,
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms/', variables('hostingPlanName'))]"
}
},
{
"apiVersion": "2015-05-01",
"name": "[parameters('functionAppName')]",
"type": "Microsoft.Insights/components",
"kind": "Web",
"location": "[parameters('location')]",
"tags": {
"[concat('hidden-link:', resourceId('Microsoft.Web/sites/', parameters('functionAppName')))]": "Resource"
},
"properties": {
"ApplicationId": "[parameters('functionAppName')]",
"Application_Type": "web"
}
}
],
"outputs": {
"principalId": {
"type": "string",
"value": "[reference(concat(resourceId('Microsoft.Web/sites/', parameters('functionAppName')), '/providers/Microsoft.ManagedIdentity/Identities/default'), '2015-08-31-PREVIEW').principalId]"
}
}
}

如果有人能帮我弄清楚为什么我在第一次运行时会遇到该错误,我将不胜感激,谢谢!

最佳答案

资源已创建,但部署操作失败,因为计算输出变量时出现问题。

很可能是由于您尝试访问应用服务的服务主体 ID 的方式所致。 “/providers/Microsoft.ManagedIdentity/Identities/default”部分。

你可能想要这样的东西:

[reference(resourceId('Microsoft.Web/sites', parameters('functionAppName')), '2016-08-01', 'Full').identity.principalId]

关于json - CI 管道失败,即使它正在做它应该做的事情,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65210580/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com