Azure DevOps yaml 管道:如何知道正在签出哪个分支?

nop*_*ace 7 azure-devops azure-pipelines azure-pipelines-yaml

目前,我的 YAML 管道和应用程序的源代码位于两个不同的分支中。

我试图找到证据证明正在检查的确实是源代码的分支,而不是我的管道的分支。

我看到末尾的签出调用git fetch是针对特定的提交,而不是针对指定的分支名称

这是我的资源定义:

resources:
  repositories:
  - repository: RepoName
    type: git
    name: 'MyRepository'  # repository in Azure DevOps
    trigger:
      branches:
        include:
        - UAT
Run Code Online (Sandbox Code Playgroud)

在我的一个步骤中,我做了一个checkout: RepoName.

我本来期待git checkout UAT在拉出源代码后,但正如所说,我看到了特定提交的签出。

我如何确定正在检查哪个分支?

Krz*_*tof 0

你需要设置ref

resources:
  repositories:
  - repository: string  # identifier (A-Z, a-z, 0-9, and underscore)
    type: enum  # see the following "Type" topic
    name: string  # repository name (format depends on `type`)
    ref: string  # ref name to use; defaults to 'refs/heads/master'
    endpoint: string  # name of the service connection to use (for types that aren't Azure Repos)
    trigger:  # CI trigger for this repository, no CI trigger if skipped (only works for Azure Repos)
      branches:
        include: [ string ] # branch names which will trigger a build
        exclude: [ string ] # branch names which will not
      tags:
        include: [ string ] # tag names which will trigger a build
        exclude: [ string ] # tag names which will not
      paths:
        include: [ string ] # file paths which must match to trigger a build
        exclude: [ string ] # file paths which will not trigger a build
Run Code Online (Sandbox Code Playgroud)

所以它会是

resources:
  repositories:
  - repository: RepoName
    type: git
    name: 'MyRepository'  # repository in Azure DevOps
    ref: 'UAT'
    trigger:
      branches:
        include:
        - UAT
Run Code Online (Sandbox Code Playgroud)