Merge pull request #19964 from Ericsson/jenkins-backend

Migrate jenkins-backend plugin to new backend system
This commit is contained in:
Patrik Oldsberg
2023-10-10 11:58:19 +02:00
committed by GitHub
10 changed files with 118 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-jenkins-backend': patch
---
Added support for the [new backend system](https://backstage.io/docs/backend-system/)
+1
View File
@@ -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:^",
+1
View File
@@ -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'));
+14
View File
@@ -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.
+5
View File
@@ -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)
+2
View File
@@ -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:^",
+1
View File
@@ -21,3 +21,4 @@
*/
export * from './service';
export { jenkinsPlugin as default } from './plugin';
@@ -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();
});
});
+64
View File
@@ -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,
}),
);
},
});
},
});
+3
View File
@@ -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:^"