diff --git a/.changeset/olive-geese-rest.md b/.changeset/olive-geese-rest.md new file mode 100644 index 0000000000..547fb828d8 --- /dev/null +++ b/.changeset/olive-geese-rest.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-jenkins-backend': patch +--- + +Added support for the [new backend system](https://backstage.io/docs/backend-system/) diff --git a/packages/backend-next/package.json b/packages/backend-next/package.json index 3e5b4f8057..e4bbf5e134 100644 --- a/packages/backend-next/package.json +++ b/packages/backend-next/package.json @@ -38,6 +38,7 @@ "@backstage/plugin-catalog-backend-module-unprocessed": "workspace:^", "@backstage/plugin-devtools-backend": "workspace:^", "@backstage/plugin-entity-feedback-backend": "workspace:^", + "@backstage/plugin-jenkins-backend": "workspace:^", "@backstage/plugin-kubernetes-backend": "workspace:^", "@backstage/plugin-lighthouse-backend": "workspace:^", "@backstage/plugin-linguist-backend": "workspace:^", diff --git a/packages/backend-next/src/index.ts b/packages/backend-next/src/index.ts index 1b4867c05e..bdfbc2c26b 100644 --- a/packages/backend-next/src/index.ts +++ b/packages/backend-next/src/index.ts @@ -29,6 +29,7 @@ backend.add( backend.add(import('@backstage/plugin-catalog-backend/alpha')); backend.add(import('@backstage/plugin-devtools-backend')); backend.add(import('@backstage/plugin-entity-feedback-backend')); +backend.add(import('@backstage/plugin-jenkins-backend')); backend.add(import('@backstage/plugin-kubernetes-backend/alpha')); backend.add(import('@backstage/plugin-lighthouse-backend')); backend.add(import('@backstage/plugin-linguist-backend')); diff --git a/plugins/jenkins-backend/README.md b/plugins/jenkins-backend/README.md index 133b9f42e2..d6f8fa5472 100644 --- a/plugins/jenkins-backend/README.md +++ b/plugins/jenkins-backend/README.md @@ -8,6 +8,20 @@ This is the backend half of the 2 Jenkins plugins and is responsible for: - finding the appropriate job(s) on that instance for an entity - connecting to Jenkins and gathering data to present to the frontend +## New Backend System + +The jenkins backend plugin has support for the [new backend system](https://backstage.io/docs/backend-system/), here's how you can set that up: + +In your `packages/backend/src/index.ts` make the following changes: + +```diff + import { createBackend } from '@backstage/backend-defaults'; + const backend = createBackend(); + // ... other feature additions + backend.add(import('@backstage/plugin-jenkins-backend')); + backend.start(); +``` + ## Integrating into a backstage instance This plugin needs to be added to an existing backstage instance. diff --git a/plugins/jenkins-backend/api-report.md b/plugins/jenkins-backend/api-report.md index fd1365547d..28dafa70bf 100644 --- a/plugins/jenkins-backend/api-report.md +++ b/plugins/jenkins-backend/api-report.md @@ -3,6 +3,7 @@ > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). ```ts +import { BackendFeature } from '@backstage/backend-plugin-api'; import { CatalogApi } from '@backstage/catalog-client'; import { CompoundEntityRef } from '@backstage/catalog-model'; import { Config } from '@backstage/config'; @@ -79,6 +80,10 @@ export interface JenkinsInstanceConfig { username: string; } +// @public +const jenkinsPlugin: () => BackendFeature; +export default jenkinsPlugin; + // @public (undocumented) export interface RouterOptions { // (undocumented) diff --git a/plugins/jenkins-backend/package.json b/plugins/jenkins-backend/package.json index 12fe2debe1..ff044ab73c 100644 --- a/plugins/jenkins-backend/package.json +++ b/plugins/jenkins-backend/package.json @@ -31,11 +31,13 @@ }, "dependencies": { "@backstage/backend-common": "workspace:^", + "@backstage/backend-plugin-api": "workspace:^", "@backstage/catalog-client": "workspace:^", "@backstage/catalog-model": "workspace:^", "@backstage/config": "workspace:^", "@backstage/errors": "workspace:^", "@backstage/plugin-auth-node": "workspace:^", + "@backstage/plugin-catalog-node": "workspace:^", "@backstage/plugin-jenkins-common": "workspace:^", "@backstage/plugin-permission-common": "workspace:^", "@backstage/plugin-permission-node": "workspace:^", diff --git a/plugins/jenkins-backend/src/index.ts b/plugins/jenkins-backend/src/index.ts index c55335c52d..4d01566a60 100644 --- a/plugins/jenkins-backend/src/index.ts +++ b/plugins/jenkins-backend/src/index.ts @@ -21,3 +21,4 @@ */ export * from './service'; +export { jenkinsPlugin as default } from './plugin'; diff --git a/plugins/jenkins-backend/src/plugin.test.tsx b/plugins/jenkins-backend/src/plugin.test.tsx new file mode 100644 index 0000000000..22ef6de078 --- /dev/null +++ b/plugins/jenkins-backend/src/plugin.test.tsx @@ -0,0 +1,22 @@ +/* + * Copyright 2021 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { jenkinsPlugin } from './plugin'; + +describe('jenkins', () => { + it('should export the jenkins plugin', () => { + expect(jenkinsPlugin).toBeDefined(); + }); +}); diff --git a/plugins/jenkins-backend/src/plugin.ts b/plugins/jenkins-backend/src/plugin.ts new file mode 100644 index 0000000000..8da26d62aa --- /dev/null +++ b/plugins/jenkins-backend/src/plugin.ts @@ -0,0 +1,64 @@ +/* + * Copyright 2023 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { loggerToWinstonLogger } from '@backstage/backend-common'; +import { + createBackendPlugin, + coreServices, +} from '@backstage/backend-plugin-api'; +import { DefaultJenkinsInfoProvider } from './service/jenkinsInfoProvider'; +import { createRouter } from './service/router'; +import { catalogServiceRef } from '@backstage/plugin-catalog-node/alpha'; + +/** + * Jenkins backend plugin + * + * @public + */ +export const jenkinsPlugin = createBackendPlugin({ + pluginId: 'jenkins', + register(env) { + env.registerInit({ + deps: { + logger: coreServices.logger, + permissions: coreServices.permissions, + httpRouter: coreServices.httpRouter, + config: coreServices.rootConfig, + catalogClient: catalogServiceRef, + }, + async init({ logger, permissions, httpRouter, config, catalogClient }) { + const winstonLogger = loggerToWinstonLogger(logger); + const jenkinsInfoProvider = DefaultJenkinsInfoProvider.fromConfig({ + config, + catalog: catalogClient, + }); + httpRouter.use( + await createRouter({ + permissions, + /** + * Logger for logging purposes + */ + logger: winstonLogger, + /** + * Info provider to be able to get all necessary information for the APIs + */ + jenkinsInfoProvider, + }), + ); + }, + }); + }, +}); diff --git a/yarn.lock b/yarn.lock index eda74d8b35..d2198a813e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7408,12 +7408,14 @@ __metadata: resolution: "@backstage/plugin-jenkins-backend@workspace:plugins/jenkins-backend" dependencies: "@backstage/backend-common": "workspace:^" + "@backstage/backend-plugin-api": "workspace:^" "@backstage/catalog-client": "workspace:^" "@backstage/catalog-model": "workspace:^" "@backstage/cli": "workspace:^" "@backstage/config": "workspace:^" "@backstage/errors": "workspace:^" "@backstage/plugin-auth-node": "workspace:^" + "@backstage/plugin-catalog-node": "workspace:^" "@backstage/plugin-jenkins-common": "workspace:^" "@backstage/plugin-permission-common": "workspace:^" "@backstage/plugin-permission-node": "workspace:^" @@ -25685,6 +25687,7 @@ __metadata: "@backstage/plugin-catalog-backend-module-unprocessed": "workspace:^" "@backstage/plugin-devtools-backend": "workspace:^" "@backstage/plugin-entity-feedback-backend": "workspace:^" + "@backstage/plugin-jenkins-backend": "workspace:^" "@backstage/plugin-kubernetes-backend": "workspace:^" "@backstage/plugin-lighthouse-backend": "workspace:^" "@backstage/plugin-linguist-backend": "workspace:^"