小编Mar*_*otH的帖子

是否可以在资源的 ref 属性中使用变量:Azure DevOps YAML 的存储库?

我有两个 AzureDevOps Git 分支:

master
feature/mybranch
Run Code Online (Sandbox Code Playgroud)

我在 yaml 中定义了一个多阶段构建管道,其中一些步骤被模板化为单独的 .yml 文件。

在我的外部 azure-pipelines.yml 中,我引用了我的模板 .yml 所在的存储库:

resources:
  repositories:
    - repository: templates
      type: git
      name: MyProject/MyRepo
Run Code Online (Sandbox Code Playgroud)

当我在“master”分支中构建时,一切都很好,因为默认情况下,存储库将在 refs/heads/master 中查找。

当我在功能分支中工作并且我想测试我的模板 .yml 文件的实验性更改时,我不希望它从主分支中获取它们,我希望它使用我正在工作的分支中的文件在。

以下工作并允许我这样做:

resources:
  repositories:
    - repository: templates
      type: git
      name: MyProject/MyRepo
      ref: refs/heads/feature/mybranch
Run Code Online (Sandbox Code Playgroud)

但是,当我将其合并回 master 时,我显然不希望 'ref:' 仍然指向功能分支,因此我想使用变量动态生成 'ref:' 的值。

我试过使用ref: $(Build.SourceBranch)where $(Build.SourceBranch)should expand to'refs/heads/feature/mybranch'

但它不起作用。错误:

62638: "/azure-pipelines.yml: Could not get the latest source version for repository MySolution hosted on Azure Repos using ref refs/heads/$(Build.SourceBranch)."
Run Code Online (Sandbox Code Playgroud)

yaml azure azure-devops

7
推荐指数
2
解决办法
3412
查看次数

如何在触发管道中使用以前的Azure DevOps yaml管道名称?

我有两个 Azure DevOps yaml 管道,一个用于构建,一个用于部署(是的,我知道我可以在一个管道中完成这两项工作,但对于我的用例,我需要将其拆分)。

第一个管道构建工件,然后我将第二个管道配置为在第一个管道完成部署这些工件时触发。

我试图让第二个管道与第一个管道具有相同的名称,以便轻松将两者关联起来。

因此,如果第一个管道运行并自动命名为“1.0.0”,我希望第二个管道在触发时也被命名为“1.0.0”。

我的第一个管道(如下)按如下方式启动,并具有自动生成的语义名称。

# Generate build name - see variables section below
name: '$(Version.MajorMinor).$(Version.Revision)$(Version.Suffix)'

# These are Continuous Integration Triggers for automatically starting a new pipeline run when there is a check in for any of the matching branches 
trigger:
- trunk
- feature/*
- task/*
- bug/*

# Use this section to set variables that are specific to the Microservice / Solution being processed
variables:
  Version.MajorMinor: 1.0                                         # Major = non-backward compatible version …
Run Code Online (Sandbox Code Playgroud)

azure-devops azure-pipelines

5
推荐指数
1
解决办法
1224
查看次数

标签 统计

azure-devops ×2

azure ×1

azure-pipelines ×1

yaml ×1