共用方式為


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.

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

性能

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

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

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

這很重要

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

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

ref 字串。
要簽出的 ref 名稱;默認為 『refs/heads/main』。 每當資源觸發程式引發時,預設就會取出分支。 支援範本表示式。

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

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

備註

這很重要

存放庫資源不允許在 nameref中使用管線變數。 觸發程式支援通配符。

範本表示式支援 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

另請參閱