将文件引用作为参数传递给Azure YAML部署中另一个仓库的插入步骤

问题描述

我有一个基于yaml的作业的存储库,我想在许多yaml脚本中重复使用。但是,将使用作业的脚本在其他存储库中。

可重用作业将文件路径作为输入参数。并且由于某种原因,在管道执行导入的作业时找不到文件

如何在主作业的参数中引用文件,以便在执行导入的作业时可以找到它?

# MyMainScriptTemplate.yml that will be executed by the pipeline 

trigger:
  - master
    
resources:
  repositories:
    - repository: AzureTemplates
    type: git
    name: AzureTemplates
    
jobs:
  - template: /FunctionApp/DeployFunctionApp.yml@AzureTemplates
  parameters:
    file: /Azure/Functions/template.json #This can be found when executing ...
# ReusableJobTemplate.yml defines a job that should be referenced from the main script

parameters:
  - name: file
  type: string
    
jobs:
  - job: DeployFunctionApp
  steps:
    - task: AzureResourceManagerTemplateDeployment@3
    inputs:
      deploymentScope: "Resource Group"
      azureResourceManagerConnection: "Dev"
      subscriptionId: "XYZ"
      action: "Create Or Update Resource Group"
      resourceGroupName: "XYZ"
      location: "West Europe"
      templateLocation: "Linked artifact"
      csmFile: ${{ parameters.file }}
      deploymentMode: "Incremental"
    displayName: "Run a one-line script"

解决方法

请检查mulirepo behaves的使用方式。

我建议您执行两个步骤:

  • 在调用模板之前添加- checkout: AzureTemplates步骤
  • 并将路径从/Azure/Functions/template.json更改为(Agent.BuildDirectory)/AzureTemplates/Azure/Functions/template.json