resources.repository.repository 定義

關鍵字 repository 可讓您指定外部存放庫。 使用存放庫資源來參考管線中的其他存放庫。

repositories:
- repository: string # Required as first property. Alias for the repository.
  endpoint: string # ID of the service endpoint connecting to this repository.
  trigger: none | trigger | [ string ] # CI trigger for this repository, no CI trigger if skipped (only works for Azure Repos).
  name: string # repository name (format depends on 'type'; does not accept variables).
  ref: string # ref name to checkout; defaults to 'refs/heads/main'. The branch checked out by default whenever the resource trigger fires.
  type: string # Type of repository: git, github, githubenterprise, and bitbucket.
repositories:
- repository: string # Required as first property. Alias for the repository.
  endpoint: string # ID of the service endpoint connecting to this repository.
  trigger: none | trigger | [ string ] # CI trigger for this repository, no CI trigger if skipped (only works for Azure Repos).
  name: string # repository name (format depends on 'type'; does not accept variables).
  type: string # Type of repository: git, github, githubenterprise, and bitbucket.
  ref: string # ref name to checkout; defaults to 'refs/heads/main'. The branch checked out by default whenever the resource trigger fires. Does not accept variables.
repositories:
- repository: string # Required as first property. Alias for the repository.
  endpoint: string # ID of the service endpoint connecting to this repository.
  name: string # repository name (format depends on 'type'; does not accept variables).
  type: string # Type of repository: git, github, githubenterprise, and bitbucket.
  ref: string # ref name to checkout; defaults to 'refs/heads/main'. The branch checked out by default whenever the resource trigger fires. Does not accept variables.

參考此定義的定義: resources.repositories

屬性

repository 字串。 作為第一個屬性的必要專案。
指定存放庫的別名。 可接受的值:[-_A-Za-z0-9]*。

endpoint 字串。
連線到此存放庫的服務端點識別碼。

trigger觸發程式
此存放庫的 CI 觸發程式,如果省略 CI 觸發程式,則不會觸發任何 CI 觸發程式。

重要

  • 只有Azure Repos Git 存放庫才支援存放庫資源觸發程式。
  • 存放庫資源觸發程式不支援 batch

name 字串。
存放庫名稱。 格式取決於 'type';不接受變數。

ref 字串。
要簽出的 ref 名稱;預設為 'refs/heads/main'。 每當引發資源觸發程式時,分支預設會取出。 支援範本運算式

ref 字串。
要簽出的 ref 名稱;預設為 'refs/heads/main'。 每當引發資源觸發程式時,分支預設會取出。 不接受變數。

type 字串。
存放庫類型:git、github、githubenterprise 和 bitbucket。

備註

重要

存放庫資源不允許 和 ref 中的 name 管線變數。 觸發程式支援萬用字元。

屬性 (支援ref 範本運算式,但不支援 name 屬性) 。 觸發程式支援萬用字元。

重要

Azure Repos Git 存放庫僅支援存放庫資源觸發程式。 如需語法的詳細資訊 trigger ,包括分支標籤萬用字元支援,請參閱觸發程式定義建置Azure Repos Git 或 TFS Git 存放庫

重要

batch 存放庫資源觸發程式不支援。

如果您的管線在另 一個存放庫中有範本,您必須讓系統知道該存放庫。

如果您的管線在另 一個存放庫中有範本,或您想要搭配需要服務連線的存放庫使用 多存放庫簽出 ,則必須讓系統知道該存放庫。

類型

管線支援存放庫類型的下列值: gitgithubbitbucket 。 此 git 類型是指Azure Repos Git 存放庫。

  • 如果您指定 type: git ,此值 name 會參考Azure Repos Git 存放庫的名稱。

    • 如果您的管線與存放庫位於相同的 Azure DevOps 專案中,例如名為 tools 的存放庫,您可以使用 來參考它 name: tools
    • 如果您的管線與存放庫位於相同的 Azure DevOps 組織中,但在不同的 Azure DevOps 專案中,例如名為 ToolsProject 的專案,您必須使用專案名稱來限定存放庫名稱: name: ToolsProject/tools
  • 如果您指定 type: github ,此值 name 就是 GitHub 存放庫的完整名稱,並包含使用者或組織。 例如 name: Microsoft/vscode。 GitHub 存放庫需要 GitHub 服務連線 以進行授權。

  • 如果您指定 type: bitbucket ,此值 name 就是 Bitbucket Cloud 存放庫的完整名稱,並包含使用者或組織。 例如 name: MyBitbucket/vscode。 Bitbucket Cloud 存放庫需要 Bitbucket 雲端服務連線 以進行授權。

如需這些類型的詳細資訊,請參閱 查看管線中的多個存放庫 - 存放庫資源定義

變數

在每個回合中,存放庫資源的中繼資料可供執行時間變數形式的所有作業使用。 <Alias>是您為存放庫資源提供的識別碼。

resources.repositories.<Alias>.name
resources.repositories.<Alias>.ref
resources.repositories.<Alias>.type
resources.repositories.<Alias>.id
resources.repositories.<Alias>.url
resources.repositories.<Alias>.version

下列範例具有別名為 的 common 存放庫資源,並使用 來存取 resources.repositories.common.* 存放庫資源變數。

resources:
  repositories:
    - repository: common
      type: git
      ref: main
      name: Repo

variables:
  ref: $[ resources.repositories.common.ref ]
  name: $[ resources.repositories.common.name ]
  id: $[ resources.repositories.common.id ]
  type: $[ resources.repositories.common.type ]
  url: $[ resources.repositories.common.url ]
  version: $[ resources.repositories.common.version ]

steps:
- bash: |
    echo "name = $(name)"
    echo "ref = $(ref)"
    echo "id = $(id)"
    echo "type = $(type)"
    echo "url = $(url)"
    echo "version = $(version)"

變數

在每個回合中,存放庫資源的中繼資料可供執行時間變數形式的所有作業使用。 <Alias>是您為存放庫資源提供的識別碼。

resources.repositories.<Alias>.name
resources.repositories.<Alias>.ref
resources.repositories.<Alias>.type
resources.repositories.<Alias>.id
resources.repositories.<Alias>.url

下列範例具有別名為 的 common 存放庫資源,並使用 來存取 resources.repositories.common.* 存放庫資源變數。

resources:
  repositories:
    - repository: common
      type: git
      ref: main
      name: Repo

variables:
  ref: $[ resources.repositories.common.ref ]
  name: $[ resources.repositories.common.name ]
  id: $[ resources.repositories.common.id ]
  type: $[ resources.repositories.common.type ]
  url: $[ resources.repositories.common.url ]

steps:
- bash: |
    echo "name = $(name)"
    echo "ref = $(ref)"
    echo "id = $(id)"
    echo "type = $(type)"
    echo "url = $(url)"

範例

resources:
  repositories:
  - repository: common
    type: github
    name: Contoso/CommonTools
    endpoint: MyContosoServiceConnection

另請參閱