gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 06:51:23 25 4
gpt4 key购买 nike

我正在使用 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 shouldtrigger 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com