2

我目前在两个不同的分支中有我的 yaml 管道和我的应用程序的源代码,我试图找到证据证明正在签出的确实是源代码的分支,而不是我的管道的分支,但我看到 checkout 调用在末尾git fetch 是针对特定的提交,而不是针对指定的分支名称。这是我的资源定义:

resources:
  repositories:
  - repository: RepoName
    type: git
    name: 'MyRepository'  # repository in Azure DevOps
    trigger:
      branches:
        include:
        - UAT

在我的一个步骤中,我做了一个checkout: RepoName. 我期待git checkout UAT在拉取源代码之后,但正如我所说,我看到了一个特定提交的结帐。我如何确定分支被签出?

4

3 回答 3

2

默认情况下,构建管道将检查触发当前管道运行的单个提交。当您手动或通过其他方法触发管道运行时,运行将检查默认分支或您指定的分支上的最新提交。

但是,无论哪种方法触发管道运行,您都可以使用预定义的构建变量Build.SourceBranchBuild.SourceBranchName获取从其中签出提交的分支名称。

要查看更多详细信息,您可以查看“使用预定义变量”。

另外,你也可以到本地仓库的根目录下,执行git branch命令。该命令将输出当前分支的名称。例如:

git branch --show-current

如果当前分支是主分支,则输出:

master
于 2021-01-01T07:48:36.010 回答
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

所以它会是

resources:
  repositories:
  - repository: RepoName
    type: git
    name: 'MyRepository'  # repository in Azure DevOps
    ref: 'UAT'
    trigger:
      branches:
        include:
        - UAT
于 2020-12-14T14:45:18.963 回答
0

ref属性中,您可以这样设置:ref: 'refs/heads/UAT'

resources:
  repositories:
  - repository: RepoName
    type: git
    name: 'MyRepository'  # repository in Azure DevOps
    ref: 'refs/heads/UAT'
    trigger:
      branches:
        include:
        - UAT

然后在steps,你需要添加- checkout: RepoName

这是我的示例,您可以参考:

pool:
  vmImage: 'windows-2019'

trigger: none

resources:
      repositories:
      - repository: RepoName
        type: git
        name: '{proName}/{repoName}'  # repository in Azure DevOps
        ref: 'refs/heads/dev'    

steps:
  - checkout: RepoName

在构建摘要页面中:

在此处输入图像描述

在日志中:

在此处输入图像描述

于 2020-12-18T09:15:21.737 回答