Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add azure:pipeline:run scaffolder action #1358

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Prev Previous commit
Next Next commit
add template for the pipeline api with v14 of node-api
Signed-off-by: Phillip Morton <Phiph@users.noreply.github.com>

Signed-off-by: Phill Morton <Phiph@users.noreply.github.com>
  • Loading branch information
Phiph committed Oct 22, 2024
commit ad664d311596c931000b5ffd5221744d4383c34a
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
},
"dependencies": {
"@backstage/backend-plugin-api": "^0.7.0",
"@backstage/plugin-scaffolder-node": "^0.4.8"
"@backstage/errors": "^1.2.4",
"@backstage/integration": "^1.13.0",
"@backstage/plugin-scaffolder-node": "^0.4.8",
"azure-devops-node-api": "^14.0.0"
},
"devDependencies": {
"@backstage/backend-common": "^0.23.3",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { createTemplateAction } from '@backstage/plugin-scaffolder-node';
import {
DefaultAzureDevOpsCredentialsProvider,
ScmIntegrationRegistry,
} from '@backstage/integration';

import { InputError } from '@backstage/errors';
import { getBearerHandler, getPersonalAccessTokenHandler, WebApi } from 'azure-devops-node-api';

/**
* Creates an `acme:example` Scaffolder action.
Expand All @@ -9,31 +16,97 @@ import { createTemplateAction } from '@backstage/plugin-scaffolder-node';
*
* @public
*/
export function createAcmeExampleAction() {
export function runAzurePipelineAction(options: {
integrations: ScmIntegrationRegistry;
config: Config;
}) {
const { integrations, config } = options;

// For more information on how to define custom actions, see
// https://backstage.io/docs/features/software-templates/writing-custom-actions
return createTemplateAction<{
myParameter: string;
host: string;
organization: string;
pipelineId: string;
project: string;
branch?: string;
token?: string;
pipelineParameters?: object;
pipelineVariables?: object;
}>({
id: 'acme:example',
description: 'Runs Yeoman on an installed Yeoman generator',
id: "azure:pipeline:run",
schema: {
input: {
type: 'object',
required: ['myParameter'],
required: [
"organization",
"pipelineId",
"project"
],
type: "object",
properties: {
myParameter: {
title: 'An example parameter',
description: 'This is the schema for our example parameter',
type: 'string',
server: {
type: "string",
title: "Host",
description: "The host of Azure DevOps. Defaults to dev.azure.com",
},
organization: {
type: "string",
title: "Organization",
description: "The name of the Azure DevOps organization.",
},
pipelineId: {
type: "string",
title: "Pipeline ID",
description: "The pipeline ID.",
},
project: {
type: "string",
title: "Project",
description: "The name of the Azure project.",
},
branch: {
title: "Repository Branch",
type: "string",
description: "The branch of the pipeline's repository.",
},
pipelineParameters: {
title: "Pipeline Parameters",
type: "object",
description: "The values you need as parameters on the request to start a build.",
},
},
},
},
async handler(ctx) {
ctx.logger.info(
`Running example template with parameters: ${ctx.input.myParameter}`,
);
const {
host = "dev.azure.com",
organization,
pipelineId,
project,
branch,
pipelineParameters
} = ctx.input;


const url = `https://${host}/${organization}`;
const credentialProvider =
DefaultAzureDevOpsCredentialsProvider.fromIntegrations(integrations);
const credentials = await credentialProvider.getCredentials({ url: url });

if (credentials === undefined && ctx.input.token === undefined) {
throw new InputError(
`No credentials provided ${url}, please check your integrations config`,
);
}

const authHandler =
ctx.input.token || credentials?.type === 'pat'
? getPersonalAccessTokenHandler(ctx.input.token ?? credentials!.token)
: getBearerHandler(credentials!.token);

const webApi = new WebApi(url, authHandler);

webApi.getPipelinesApi();

await new Promise(resolve => setTimeout(resolve, 1000));
},
Expand Down
44 changes: 44 additions & 0 deletions workspaces/azure-devops/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2835,7 +2835,10 @@ __metadata:
"@backstage/backend-common": ^0.23.3
"@backstage/backend-plugin-api": ^0.7.0
"@backstage/cli": ^0.26.11
"@backstage/errors": ^1.2.4
"@backstage/integration": ^1.13.0
"@backstage/plugin-scaffolder-node": ^0.4.8
azure-devops-node-api: ^14.0.0
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -14943,12 +14946,21 @@ __metadata:
linkType: hard

"azure-devops-node-api@npm:^14.0.0":
<<<<<<< HEAD
version: 14.1.0
resolution: "azure-devops-node-api@npm:14.1.0"
dependencies:
tunnel: 0.0.6
typed-rest-client: 2.1.0
checksum: 4b459ee2dbedc068789234229166e7fe1833c42803aa7dad52c5178b0692736585a1903a760498b8ee0993f886add0d3c2e9a84b6f7b9ed2aab3ae108f47e07c
=======
version: 14.0.2
resolution: "azure-devops-node-api@npm:14.0.2"
dependencies:
tunnel: 0.0.6
typed-rest-client: ^2.0.1
checksum: 26f39c7772d313befd49696fe2a1e91a8ffd75cfeb0c7f305a7102867f1090d299544361663b14e99bbebbf5855d1fc56ead0e4e32ee53bc83b487cdbe30d254
>>>>>>> 3a0a6213 (add template for the pipeline api with v14 of node-api)
languageName: node
linkType: hard

Expand Down Expand Up @@ -17992,6 +18004,16 @@ __metadata:
languageName: node
linkType: hard

"des.js@npm:^1.1.0":
version: 1.1.0
resolution: "des.js@npm:1.1.0"
dependencies:
inherits: ^2.0.1
minimalistic-assert: ^1.0.0
checksum: 0e9c1584b70d31e20f20a613fc9ef60fbc6a147dfec9e448a168794a4b97ac04d8dc47ea008f1fa93b0f8aaf7c1ead632a5e59ce1913a6079d2d244c9f5ebe33
languageName: node
linkType: hard

"destroy@npm:1.2.0, destroy@npm:^1.0.4":
version: 1.2.0
resolution: "destroy@npm:1.2.0"
Expand Down Expand Up @@ -28678,6 +28700,15 @@ __metadata:
languageName: node
linkType: hard

"qs@npm:^6.10.3":
version: 6.13.0
resolution: "qs@npm:6.13.0"
dependencies:
side-channel: ^1.0.6
checksum: e9404dc0fc2849245107108ce9ec2766cde3be1b271de0bf1021d049dc5b98d1a2901e67b431ac5509f865420a7ed80b7acb3980099fe1c118a1c5d2e1432ad8
languageName: node
linkType: hard

"qs@npm:~6.5.2":
version: 6.5.3
resolution: "qs@npm:6.5.3"
Expand Down Expand Up @@ -32840,6 +32871,19 @@ __metadata:
languageName: node
linkType: hard

"typed-rest-client@npm:^2.0.1":
version: 2.0.2
resolution: "typed-rest-client@npm:2.0.2"
dependencies:
des.js: ^1.1.0
js-md4: ^0.3.2
qs: ^6.10.3
tunnel: 0.0.6
underscore: ^1.12.1
checksum: f1d9a0ffd5b7266f01df9ea4eb08b8da04793cf6902d82b3c6a46d1328cdefe80bb0cfc8f96afa645077c234ec218d8b16f642da35c1e2f1adf3d61a5904d8d1
languageName: node
linkType: hard

"typedarray@npm:^0.0.6":
version: 0.0.6
resolution: "typedarray@npm:0.0.6"
Expand Down