我如何知道哪个 git 分支触发了我的 ADO 管道?

How can I know which git branch triggered my ADO pipeline?

我希望我的 ADO 管道具有不同的阶段 运行,具体取决于条件的结果。对于这种情况,我想将分支名称(将管道触发到 运行 的分支名称)与字符串文字进行比较。在我可以动态访问该分支的名称之前,我无法执行此操作。

例如,我不希望我的生产阶段为 运行,除非触发该阶段的分支名为 master

我熟悉用于获取存储库名称的预定义变量 Build.Repository.Name,但我真正需要的是 分支 的名称触发管道的存储库。

那么,是否有一个变量保存我的触发分支的名称?如果是,那是什么?

I found the solution to my problem in Microsoft's Azure Pipeline documentation.

Build.SourceBranch

The branch of the triggering repo the build was queued for. Some examples:

Git repo branch: refs/heads/master

Git repo pull request: refs/pull/1/merge