azure pipeline - 根据触发路径设置变量

标签 azure azure-pipelines azure-pipelines-yaml

我正在使用 Azure Pipelines 并遇到以下情况:

我有一个包含文件夹 A 和 B 的存储库(将来还会有更多)。如果我手动运行管道,我会选择 A 或 B,并且管道会处理该文件夹中的文件。 这对于我的分支来说很好,但我也希望我的主分支有一个自动触发器。

如何获取依赖于代码更改路径的变量?

我的触发器看起来像这样:

trigger:
  branches:
    include:
      - main
  paths:
    include:
      - abc/xyz/A/*
      - abc/xyz/B/*

我现在需要的只是一个变量 A 或 B,具体取决于发生更改的路径。 (理想情况下,如果两个文件夹中都有更改,管道应该触发两次,但这是我必须解决的下一个问题)

最佳答案

没有直接的方法可以实现这一点。

作为解决方法,您可以使用 git 命令从 A 和 B 中的代码更改中获取提交消息,并将提交消息设置为变量。

git diff-tree --no-commit-id --name-only -r $(Build.SourceVersion)

如果更改来自文件夹 A。将“FolderAUpdated”设置为 ture

Write-Host "##vso[task.setvariable variable=FolderAUpdated]true"

并设置条件来检查变量值

“自定义条件”:and(succeeded(), eq(variables['FolderAUpdated'], 'true'))

"(Ideally if there are changes in both folders the pipeline should trigger twice, but this is the next problem I have to take on)"

一个好的选择是创建两个单独的管道,如果两个文件夹都有更改,则会触发两个管道。

管道A

trigger:
  branches:
    include:
      - main
  paths:
    include:
      - abc/xyz/A/*

管道B

trigger:
  branches:
    include:
      - main
  paths:
    include:
      - abc/xyz/B/*

关于azure pipeline - 根据触发路径设置变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73618882/

相关文章:

azure - 如果变量不等于azure pipeline yaml中的预期值,如何跳过模板?

azure - Azure Active Directory 和 Azure Active Directory 域服务之间有什么区别?

Azure 数据库导出 - 不支持高级版

azure-devops - Azure DevOps (VSTS) 管道(发布定义)排除某些阶段(环境)的构建标记

azure-pipelines - 如何强制我的 Azure 管道使用 .NET 5.0 构建?

azure - 如何从另一个存储库调用二头肌文件?

Azure DNS - 如何创建 MB 和 RP 记录?

azure - 尝试安装 python 时,Azure 批处理启动任务失败

.net - 为什么 Visual Studio 在 Azure DevOps checkin 时排除 BIN 和 OBJ 文件夹

Azure 管道任务 DotNetCoreCLI@2 - 工件的输出文件夹