我一直在尝试Azure Logic应用程序,并想找出一种方法来编码部署过程,这样我就可以设置一个包含机密和所有好东西的CI/CD管道。
因此,我开始使用yml文件,该文件提供了多种部署同一逻辑应用程序的方法。
- 在常规作业中的一个步骤中,对任务(如Connected Service、Subscription、Resource Group等(的输入参数值进行硬编码
- 做同样的事情,但在部署作业中
- 使用管道变量提取这些值,并重复为1和2
- 1和2,但这次使用标记为机密的管道变量等等
但是,每次在部署作业中运行AzureResourceManagerTemplateDeployment@3
时,它都无法找到ARM模板文件。
- 为什么部署作业无法使用未作为部署作业运行时有效的模式找到ARM模板
- 部署作业是否无权访问生成目录
- 如何帮助部署作业查找文件?我应该给它一个到模板文件的链接而不是一个模式吗
每次搜索AzureResourceManagerTemplateDeployment
任务文档时,我都会得到AzureResourceGroupDeployment
任务的文档页面,它非常相似但不相同https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-resource-group-deployment?view=azure-devops#故障排除
当我正要发布这个问题时,我在网上做了更多的搜索,发现了AzureResourceManagerTemplateDeployment的原始文档,该文档指出,如果文件是存储库的一部分,则必须在系统变量的帮助下指定ARM模板的路径。
csmFile: "$(Build.Repository.LocalPath)/**/LogicApp.json"
csmParametersFile: "$(Build.Repository.LocalPath)/**/LogicApp.parameters.json"
我可以确认,这也没有奏效。
我会错过什么?
stages:
- stage: 'HardcodedJobStage'
displayName: 'HardcodedJobStage'
jobs:
- job: 'HardcodedJob'
displayName: HardcodedJob
pool:
vmImage: ubuntu-latest
workspace:
clean: all
steps:
- task: AzureResourceManagerTemplateDeployment@3
inputs:
deploymentScope: 'Resource Group'
ConnectedServiceName: 'Subscription (e6d1dg8c-bcd6-4713-b2f1-c9a0375d687d)'
subscriptionName: 'e6d1dg8c-bcd6-4713-b2f1-c9a0375d687d'
action: 'Create Or Update Resource Group'
resourceGroupName: 'AzureLogicApp'
location: 'UK South'
templateLocation: 'Linked artifact'
csmFile: '**/LogicApp.json'
csmParametersFile: '**/LogicApp.parameters.json'
deploymentMode: 'Incremental'
- stage: 'HardCodedDeployJobStage'
displayName: 'HardCodedDeployJobStage'
jobs:
- deployment: 'HardCodedDeployJob'
displayName: HardCodedDeployJob
pool:
vmImage: ubuntu-latest
workspace:
clean: all
environment: development
strategy:
runOnce:
deploy:
steps:
- task: AzureResourceManagerTemplateDeployment@3
inputs:
deploymentScope: 'Resource Group'
ConnectedServiceName: 'Subscription (e6d1dg8c-bcd6-4713-b2f1-c9a0375d687d)'
subscriptionName: 'e6d1dg8c-bcd6-4713-b2f1-c9a0375d687d'
action: 'Create Or Update Resource Group'
resourceGroupName: 'AzureLogicApp'
location: 'UK South'
templateLocation: 'Linked artifact'
csmFile: '**/LogicApp.json'
csmParametersFile: '**/LogicApp.parameters.json'
deploymentMode: 'Incremental'
这里的问题是,我必须将模板作为工件发布,并在阶段之间共享。
因此,我使用CopyFiles
任务将ARM模板json文件复制到一个文件夹中,然后使用PublishPipelineArtifact
任务将内容发布为管道工件。这可以在后面的阶段使用DownloadPipelineArtifact
任务进行引用。
现在我的YAML看起来像:
stages:
- stage: 'HardcodedJobStage'
displayName: 'HardcodedJobStage'
jobs:
- job: 'HardcodedJob'
displayName: HardcodedJob
pool:
vmImage: ubuntu-latest
workspace:
clean: all
steps:
- task: AzureResourceManagerTemplateDeployment@3
inputs:
deploymentScope: 'Resource Group'
ConnectedServiceName: 'Subscription (e6d1dg8c-bcd6-4713-b2f1-c9a0375d687d)'
subscriptionName: 'e6d1dg8c-bcd6-4713-b2f1-c9a0375d687d'
action: 'Create Or Update Resource Group'
resourceGroupName: 'AzureLogicApp'
location: 'UK South'
templateLocation: 'Linked artifact'
csmFile: '**/LogicApp.json'
csmParametersFile: '**/LogicApp.parameters.json'
deploymentMode: 'Incremental'
- task: CopyFiles@2
inputs:
Contents: $(Build.SourcesDirectory)/AzureLogicApp/**/*.json
targetFolder: $(Build.ArtifactStagingDirectory)
- task: PublishPipelineArtifact@1
inputs:
targetPath: $(Build.ArtifactStagingDirectory)
artifactName: armtemplate
- stage: 'HardCodedDeployJobStage'
displayName: 'HardCodedDeployJobStage'
jobs:
- deployment: 'HardCodedDeployJob'
displayName: HardCodedDeployJob
pool:
vmImage: ubuntu-latest
workspace:
clean: all
environment: development
strategy:
runOnce:
deploy:
steps:
- task: DownloadPipelineArtifact@2
inputs:
artifact: armtemplate
- task: AzureResourceManagerTemplateDeployment@3
inputs:
deploymentScope: 'Resource Group'
ConnectedServiceName: 'Subscription (e6d1dg8c-bcd6-4713-b2f1-c9a0375d687d)'
subscriptionName: 'e6d1dg8c-bcd6-4713-b2f1-c9a0375d687d'
action: 'Create Or Update Resource Group'
resourceGroupName: 'AzureLogicApp'
location: 'UK South'
templateLocation: 'Linked artifact'
csmFile: $(Pipeline.Workspace)/armtemplate/**/LogicApp.json
csmParametersFile: $(Pipeline.Workspace)/armtemplate/**/LogicApp.parameters.json
deploymentMode: 'Incremental'
假设您的yml管道与LogicApp json文件定义在同一个git存储库中,您可以使用csmFile作为绝对路径,其中"root"是git repo根文件夹。例如,如果你的logicalapp文件在/app/logicalapp/logicapp.json中,而你的yml管道在同一个git repo中,但可能在/pelines/pelinee.yml中,那么你可以将csmFile的值设置为app/logicalapp/LLogicApp.json(csmParametersFile也是如此(。