【问题标题】:Azure build pipeline yaml template referenceAzure 构建管道 yaml 模板参考
【发布时间】:2019-09-07 13:09:15
【问题描述】:

我有一个步骤定义模板,打算在构建管道中使用。 步骤定义的位置与构建管道本身不在同一文件夹下。

在管道验证期间,AzureDevops 将构建管道的位置视为根位置。这是附加到引用的路径

考虑以下代码层次结构示例

 azure
   |----products
           |----resource-type1
                        |----step-def.yaml
           |----resource-type2
                        |----step-def.yaml
   |----solutions
           |----solution1
                    |----local-step-def.yaml
                    |----build.yaml
           |----solution2
                    |----build.yaml

当 build.yaml 如下时,以下工作

jobs:
- job: Linux
  pool:
    vmImage: 'ubuntu-16.04'
  steps:
  - template: solution1/local-step-def.yml

如果你改变模板引用如下,它不起作用

  - template: ../products/resource-type1/step-def.yml

在管道上完成验证后,azure-devops 映射到

# <path-of-the-build-pipeline>/<template-ref>
azure/solutions/solution1/<template-reference>

这是文档,https://docs.microsoft.com/en-us/azure/devops/pipelines/process/templates?view=azure-devops#step-re-use

那么如何映射到产品文件夹层次结构中的 step-def.yaml 文件?

【问题讨论】:

  • 我知道答案已经晚了,但也许它可能对某人有帮助,你必须导航上面的 2 个文件夹才能工作的相对路径,即 .../../products/resource-type1/ step-def.yml .
  • @Dhruv .. 抱歉,但在使用管道开头声明的宏语法变量时,这不起作用。
  • 我认为@Nuurek 的回答应该有效

标签: azure-devops yaml azure-pipelines


【解决方案1】:

我发现只有一种解决方案可以真正做到这一点。您可以使用绝对路径来引用父目录。关键是使用系统变量填充根路径。您的示例的解决方案:

jobs:
- job: Linux
  pool:
    vmImage: 'ubuntu-16.04'
  steps:
  - template: ${{variables['System.DefaultWorkingDirectory']}}/products/resource-type1/step-def.yml

【讨论】:

    【解决方案2】:

    您可以尝试使用repositoryResource 语法,尽管它是同一个存储库,例如

    resources:
      repositories:
        - repository: pckgtemplates #resource name to be used in the build pipeline
          type: git #Azure git 
          name: packages/packagesRepo
    
    jobs:
    - template: templates\version.file.yml@pckgtemplates  
      parameters:
        versionFile: versionFile
    

    - template: templates\version.file.yml@pckgtemplates 这引用了pckgtemplates 资源的templates 文件夹中的version.file.yml 模板。

    并且pckgtemplate资源引用了当前组织的packages项目和packagesRepo存储库。

    使用这个你可以定义引用同一个项目和products/resource-type1/step-def.yml模板的资源

    【讨论】:

      猜你喜欢
      • 2020-06-22
      • 2020-06-12
      • 1970-01-01
      • 2019-05-14
      • 1970-01-01
      • 2020-05-28
      • 1970-01-01
      • 1970-01-01
      • 2022-11-03
      相关资源
      最近更新 更多