使用 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.存储库
性能
repository
字符串。 必需为第一个属性。
指定存储库的别名。 可接受的值:[-_A-Za-z0-9]*。
endpoint
字符串。
连接到此存储库的服务终结点 ID。
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。
注解
重要
存储库资源不允许 name
和 ref
中的管道变量。 触发器支持通配符。
重要
仅 Azure Repos Git 存储库支持存储库资源触发器。 有关 trigger
语法的详细信息,包括 通配符支持,分支 和 标记,请参阅 触发器定义 和 生成 Azure Repos Git 或 TFS Git 存储库。
重要
存储库资源触发器不支持 batch
。
类型
管道支持存储库类型的以下值:git
、github
和 bitbucket
。
git
类型是指 Azure Repos Git 存储库。
如果指定
type: git
,则name
值引用 Azure Repos Git 存储库的名称。- 如果管道与存储库位于同一 Azure DevOps 项目中,例如名为
tools
的存储库,则使用name: tools
引用它。 - 如果管道与存储库位于同一 Azure DevOps 组织中,但在另一个 Azure DevOps 项目中(例如名为
ToolsProject
的项目)中,则必须使用项目名称限定存储库名称:name: ToolsProject/tools
。
- 如果管道与存储库位于同一 Azure DevOps 项目中,例如名为
如果指定
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