Skip to main content

发现 Bitbucket 服务器

Bitbucket Server集成有一个特殊的实体提供程序,用于发现位于Bitbucket Server中的目录文件。 该提供程序会搜索你的Bitbucket Server账户,并将与配置路径匹配的目录文件注册为位置实体,然后通过以下处理步骤添加所有包含的目录实体。 这可以作为静态位置或手动添加目录的替代方法。

安装

您必须在后端目录初始化代码中添加实体提供程序。 该提供程序默认情况下没有安装,因此您必须将依赖关系添加到@backstage/plugin-catalog-backend-module-bitbucket-server到您的后端软件包。

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

然后将实体提供程序添加到目录生成器中:

packages/backend/src/plugins/catalog.ts
import { BitbucketServerEntityProvider } from '@backstage/plugin-catalog-backend-module-bitbucket-server';

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

// ..
}

配置

要使用实体提供程序,您需要一个Bitbucket 服务器集成设置.

此外,您还需要配置实体提供程序实例:

app-config.yaml
catalog:
providers:
bitbucketServer:
yourProviderId: # identifies your ingested dataset
host: 'bitbucket.mycompany.com'
catalogPath: /catalog-info.yaml # default value
filters: # optional
projectKey: '^apis-.*$' # optional; RegExp
repoSlug: '^service-.*$' # optional; RegExp
schedule: # 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 }
  • host: The host of the Bitbucket Server instance, note: the host needs to registered as an integration as well, see location. * catalogPath (optional): Default: /catalog-info.yaml. Path where to look for catalog-info.yaml files. When started with /, it is an absolute path from the repo root. * filters (optional): - projectKey (optional): Regular expression used to filter results based on the project key. - repoSlug (optional): Regular expression used to filter results based on the repo slug. * 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 time that should pass before the first invocation happens. - scope (optional): 'global' or 'local'. Sets the scope of concurrency control.

自定义位置处理

Bitbucket 服务器实体提供程序默认情况下会为每个匹配的版本库发出一个位置信息,但也可以覆盖此功能,并完全控制如何处理每个匹配的版本库。

BitbucketServerEntityProvider.fromConfig需要一个可选参数options.parser您可以在其中设置自己的解析器,以便用于每个匹配的版本库。

const provider = BitbucketServerEntityProvider.fromConfig(env.config, {
logger: env.logger,
schedule: env.scheduler,
parser: async function* customLocationParser(options: {
location: LocationSpec;
client: BitbucketServerClient;
}) {
// Custom logic for interpreting the matching repository
// See defaultBitbucketServerLocationParser for an example
},
});