Skip to main content

Azure DevOps 发现

Azure DevOps 集成有一个特殊的实体提供程序,用于在 Azure DevOps 中发现目录实体。 该提供程序将抓取你的 Azure DevOps 组织,并注册与配置路径匹配的实体。 这可以替代静态位置或手动添加到目录中。

本指南介绍如何安装和配置 Azure DevOps 实体提供程序(推荐)或 Azure DevOps 处理器。

依赖关系​

代码搜索功能​

Azure 发现由 Azure DevOps 中的代码搜索功能驱动,默认情况下可能未启用。 对于 Azure DevOps 服务,可以通过查看组织设置中已安装的扩展来确认。 对于 Azure DevOps 服务器,可以在集合设置中找到此信息。

如果 "代码搜索 "扩展没有列出,则可以从Visual Studio 市场.

Azure 集成​

设置Azure 集成与host和token主机必须dev.azure.com对于云用户,请将其设置为您的内部主机名。

安装​

在配置中,您可以添加一个或多个提供商配置:

app-config.yaml
catalog:
providers:
azureDevOps:
yourProviderId: # identifies your dataset / provider independent of config changes
organization: myorg
project: myproject
repository: service-* # this will match all repos starting with service-*
path: /catalog-info.yaml
schedule: # optional; same options as in TaskScheduleDefinition
# supports cron, ISO duration, "human duration" as used in code
frequency: { minutes: 30 }
# supports ISO duration, "human duration" as used in code
timeout: { minutes: 3 }
yourSecondProviderId: # identifies your dataset / provider independent of config changes
organization: myorg
project: '*' # this will match all projects
repository: '*' # this will match all repos
path: /catalog-info.yaml
anotherProviderId: # another identifier
organization: myorg
project: myproject
repository: '*' # this will match all repos
path: /src/*/catalog-info.yaml # this will search for files deep inside the /src folder
yetAnotherProviderId: # guess, what? Another one :)
host: selfhostedazure.yourcompany.com
organization: myorg
project: myproject
branch: development

可用的参数有

  • host: (optional) Leave empty for Cloud hosted, otherwise set to your self-hosted instance host. * organization: Your Organization slug (or Collection for on-premise users). Required. * project: (required) Your project slug. Wildcards are supported as shown on the examples above. Using '*' will search all projects. For a project name containing spaces, use both single and double quotes as in project: '"My Project Name"'. * repository: (optional) The repository name. Wildcards are supported as show on the examples above. If not set, all repositories will be searched. * path: (optional) Where to find catalog-info.yaml files. Defaults to /catalog-info.yaml. * branch: (optional) The branch name to use. * schedule: - frequency: How often you want the task to run. The system does its best to avoid overlapping invocations. - timeout: The maximum amount of time that a single task invocation can take. - initialDelay (optional): The amount of ti

注:_

  • 路径参数遵循与 Azure DevOps Web 界面搜索相同的规则。有关详细信息,请访问官方搜索文档。 * 要使用分支参数,必须将所需分支添加到 Azure DevOps Repositories 中的 "可搜索分支 "列表中。为此,请按照以下说明操作:

1.访问 Azure DevOps 并打开要添加分支的版本库 2.单击屏幕左下角的 "设置" 3.选择左侧导航栏中的 "选项 "选项 4.在 "可搜索分支 "部分,单击 "添加 "按钮添加新分支 5.在出现的窗口中输入要添加的分支名称,然后单击 "添加" 6.添加的分支现在将出现在 "可搜索分支 "列表中。

由于该提供程序不属于默认提供程序,因此首先需要安装 Azure 目录插件:

# From your Backstage root directory
yarn add --cwd packages/backend @backstage/plugin-catalog-backend-module-azure

完成后,您还需要将以下段落添加到packages/backend/src/plugins/catalog.ts:

packages/backend/src/plugins/catalog.ts
import { AzureDevOpsEntityProvider } from '@backstage/plugin-catalog-backend-module-azure';

const builder = await CatalogBuilder.create(env);
/** ... other processors and/or providers ... */
builder.addEntityProvider(
AzureDevOpsEntityProvider.fromConfig(env.config, {
logger: env.logger,
// optional: alternatively, use scheduler with schedule defined in app-config.yaml
schedule: env.scheduler.createScheduledTaskRunner({
frequency: { minutes: 30 },
timeout: { minutes: 3 },
}),
// optional: alternatively, use schedule
scheduler: env.scheduler,
}),
);

替代处理器​

作为实体提供者的替代方案AzureDevOpsEntityProvider您仍然可以使用AzureDevopsDiscoveryProcessor.

packages/backend/src/plugins/catalog.ts
import { AzureDevOpsDiscoveryProcessor } from '@backstage/plugin-catalog-backend-module-azure';

export default async function createPlugin(
env: PluginEnvironment,
): Promise<Router> {
const builder = await CatalogBuilder.create(env);
builder.addProcessor(
AzureDevOpsDiscoveryProcessor.fromConfig(env.config, {
logger: env.logger,
}),
);

// ..
}
catalog:
locations:
# Scan all repositories for a catalog-info.yaml in the root of the default branch
- type: azure-discovery
target: https://dev.azure.com/myorg/myproject
# Or use a custom pattern for a subset of all repositories with default repository
- type: azure-discovery
target: https://dev.azure.com/myorg/myproject/_git/service-*
# Or use a custom file format and location
- type: azure-discovery
target: https://dev.azure.com/myorg/myproject/_git/*?path=/src/*/catalog-info.yaml

注意azure-discovery类型,因为它不是常规的url处理器。

使用自定义模式时,目标由五个部分组成:

  • 基本实例 URL,本例中为 https://dev.azure.com * 组织名称,本例中为 myorg * 项目名称,本例中为 myproject ,为可选项。默认值为 *,用于扫描令牌可访问的所有项目。 * 要扫描的版本库 blob,可接受 * 通配符令牌,且必须加在 _git/ 之后。可以简单地使用 * 来扫描项目中的所有版本库。 * 每个版本库中查找目录 YAML 文件的路径。通常为 /catalog-info.yaml、/src/*/catalog-info.yaml 或类似的变体,用于存储在每个版本库根目录中的目录文件。