From 2e11317c16645c09d315fe762037601d678c5027 Mon Sep 17 00:00:00 2001 From: Ayush More Date: Fri, 17 Oct 2025 15:55:40 +0000 Subject: [PATCH 1/3] fix: update Jenkins plugin buildJob action and package.json Signed-off-by: Ayush More --- .../README.md | 12 ++++++----- .../src/actions/job/build.ts | 21 +++++++++---------- .../src/actions/job/enable.ts | 2 +- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/workspaces/jenkins/plugins/scaffolder-backend-module-jenkins/README.md b/workspaces/jenkins/plugins/scaffolder-backend-module-jenkins/README.md index 1808c00780..2518f65e6c 100644 --- a/workspaces/jenkins/plugins/scaffolder-backend-module-jenkins/README.md +++ b/workspaces/jenkins/plugins/scaffolder-backend-module-jenkins/README.md @@ -90,11 +90,13 @@ Below, there is an example for each action ```yaml - id: jenkins-job-build - name: Jenkins Job Build - action: jenkins:job:build - input: - jobName: first-job - jobParameters: some-value + name: Jenkins Job Build + action: jenkins:job:build + input: + jobName: first-job + jobParameters: + parameters: + PARAM1: value1 ``` - Copy job diff --git a/workspaces/jenkins/plugins/scaffolder-backend-module-jenkins/src/actions/job/build.ts b/workspaces/jenkins/plugins/scaffolder-backend-module-jenkins/src/actions/job/build.ts index 2f7dda7bc9..7cef100ba3 100644 --- a/workspaces/jenkins/plugins/scaffolder-backend-module-jenkins/src/actions/job/build.ts +++ b/workspaces/jenkins/plugins/scaffolder-backend-module-jenkins/src/actions/job/build.ts @@ -13,30 +13,29 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + import { createTemplateAction } from '@backstage/plugin-scaffolder-node'; import Jenkins from 'jenkins'; +import { z } from 'zod'; /** - * - * This buildJob function, creates a template action for running a Jenkins job - * - * @param jenkins - The client to interact with jenkins instance - * @returns Empty response, in case of error an exception will be thrown by jenkins client + * Create a scaffolder action to trigger a Jenkins job. */ export function buildJob(jenkins: Jenkins) { return createTemplateAction({ id: 'jenkins:job:build', - description: 'Run an existing job jenkins given a name', + description: 'Run an existing Jenkins job given its name', schema: { - input: { - jobName: z => z.string({ description: 'Name of jenkins item' }), - jobParameters: z => z.record(z.any()).optional(), - }, + input: z.object({ + jobName: z.string().describe('Name of the Jenkins job to run'), + jobParameters: z.record(z.any()).optional(), + }), }, async handler(ctx) { - ctx.logger.info(`Starting jenkins job ${ctx.input.jobName}`); + ctx.logger.info(`Starting Jenkins job: ${ctx.input.jobName}`); await jenkins.job.build(ctx.input.jobName, ctx.input.jobParameters); + ctx.logger.info('Job started successfully!'); }, }); diff --git a/workspaces/jenkins/plugins/scaffolder-backend-module-jenkins/src/actions/job/enable.ts b/workspaces/jenkins/plugins/scaffolder-backend-module-jenkins/src/actions/job/enable.ts index 535a376674..1220923017 100644 --- a/workspaces/jenkins/plugins/scaffolder-backend-module-jenkins/src/actions/job/enable.ts +++ b/workspaces/jenkins/plugins/scaffolder-backend-module-jenkins/src/actions/job/enable.ts @@ -25,7 +25,7 @@ import Jenkins from 'jenkins'; export function enableJob(jenkins: Jenkins) { return createTemplateAction({ id: 'jenkins:job:enable', - description: 'Destroy an existing job jenkins given a name', + description: 'Enable an existing Jenkins job given a name', schema: { input: { jobName: z => z.string({ description: 'Name of jenkins item' }), From 4d9459a35d75ee3638c74fe9ff88bf73e970548f Mon Sep 17 00:00:00 2001 From: Ayush More Date: Fri, 17 Oct 2025 17:03:36 +0000 Subject: [PATCH 2/3] fix: update Jenkins plugin Signed-off-by: Ayush More --- .../package.json | 3 ++- .../src/actions/job/build.ts | 25 +++++++++++-------- workspaces/jenkins/yarn.lock | 8 ++++++ 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/workspaces/jenkins/plugins/scaffolder-backend-module-jenkins/package.json b/workspaces/jenkins/plugins/scaffolder-backend-module-jenkins/package.json index 1a97f6ed5b..5175886450 100644 --- a/workspaces/jenkins/plugins/scaffolder-backend-module-jenkins/package.json +++ b/workspaces/jenkins/plugins/scaffolder-backend-module-jenkins/package.json @@ -35,7 +35,8 @@ "@backstage/errors": "backstage:^", "@backstage/plugin-scaffolder-node": "backstage:^", "cross-fetch": "^4.0.0", - "jenkins": "^1.1.0" + "jenkins": "^1.1.0", + "zod": "^4.1.12" }, "devDependencies": { "@backstage/cli": "backstage:^" diff --git a/workspaces/jenkins/plugins/scaffolder-backend-module-jenkins/src/actions/job/build.ts b/workspaces/jenkins/plugins/scaffolder-backend-module-jenkins/src/actions/job/build.ts index 7cef100ba3..d6e019fec4 100644 --- a/workspaces/jenkins/plugins/scaffolder-backend-module-jenkins/src/actions/job/build.ts +++ b/workspaces/jenkins/plugins/scaffolder-backend-module-jenkins/src/actions/job/build.ts @@ -1,5 +1,5 @@ /* - * Copyright 2024 The Backstage Authors + * Copyright 2025 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. @@ -13,29 +13,32 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - import { createTemplateAction } from '@backstage/plugin-scaffolder-node'; import Jenkins from 'jenkins'; -import { z } from 'zod'; - /** - * Create a scaffolder action to trigger a Jenkins job. + * + * This buildJob function, creates a template action for running a Jenkins job + * + * @param jenkins - The client to interact with jenkins instance + * @returns Empty response, in case of error an exception will be thrown by jenkins client */ export function buildJob(jenkins: Jenkins) { return createTemplateAction({ id: 'jenkins:job:build', description: 'Run an existing Jenkins job given its name', schema: { - input: z.object({ - jobName: z.string().describe('Name of the Jenkins job to run'), - jobParameters: z.record(z.any()).optional(), - }), + input: z => + z.object({ + jobName: z.string().describe('Name of the Jenkins job to run'), + jobParameters: z.record(z.any()).optional(), + delay: z.number().optional(), + token: z.string().optional(), + }), }, + async handler(ctx) { ctx.logger.info(`Starting Jenkins job: ${ctx.input.jobName}`); - await jenkins.job.build(ctx.input.jobName, ctx.input.jobParameters); - ctx.logger.info('Job started successfully!'); }, }); diff --git a/workspaces/jenkins/yarn.lock b/workspaces/jenkins/yarn.lock index 113144f14f..30284efd33 100644 --- a/workspaces/jenkins/yarn.lock +++ b/workspaces/jenkins/yarn.lock @@ -1751,6 +1751,7 @@ __metadata: "@backstage/plugin-scaffolder-node": "backstage:^" cross-fetch: "npm:^4.0.0" jenkins: "npm:^1.1.0" + zod: "npm:^4.1.12" languageName: unknown linkType: soft @@ -31103,6 +31104,13 @@ __metadata: languageName: node linkType: hard +"zod@npm:^4.1.12": + version: 4.1.12 + resolution: "zod@npm:4.1.12" + checksum: 10/c5f04e6ac306515c4db6ef73cf7705f521c7a2107c8c8912416a0658d689f361db9bee829b0bf01ef4a22492f1065c5cbcdb523ce532606ac6792fd714f3c326 + languageName: node + linkType: hard + "zstd-codec@npm:^0.1.5": version: 0.1.5 resolution: "zstd-codec@npm:0.1.5" From 1d42a06d43f2aed4f0ccd781533abe0539706870 Mon Sep 17 00:00:00 2001 From: Ayush More Date: Sat, 25 Oct 2025 06:57:10 +0000 Subject: [PATCH 3/3] fix(jenkins): Correct buildJob parameters and enableJob description Fixes parameter passing for buildJob action, updates enableJob description, corrects README example, and adds changeset. Closes #4871. Signed-off-by: Ayush More --- .../.changeset/humble-hounds-retire.md | 5 +++ .../README.md | 21 ++++++------- .../src/actions/job/build.ts | 31 +++++++++++++------ 3 files changed, 36 insertions(+), 21 deletions(-) create mode 100644 workspaces/jenkins/.changeset/humble-hounds-retire.md diff --git a/workspaces/jenkins/.changeset/humble-hounds-retire.md b/workspaces/jenkins/.changeset/humble-hounds-retire.md new file mode 100644 index 0000000000..4813c1547d --- /dev/null +++ b/workspaces/jenkins/.changeset/humble-hounds-retire.md @@ -0,0 +1,5 @@ +--- +'@backstage-community/plugin-scaffolder-backend-module-jenkins': major +--- + +fix(jenkins): Correct buildJob parameter passing & enableJob description diff --git a/workspaces/jenkins/plugins/scaffolder-backend-module-jenkins/README.md b/workspaces/jenkins/plugins/scaffolder-backend-module-jenkins/README.md index 2518f65e6c..b5f6535b28 100644 --- a/workspaces/jenkins/plugins/scaffolder-backend-module-jenkins/README.md +++ b/workspaces/jenkins/plugins/scaffolder-backend-module-jenkins/README.md @@ -66,8 +66,8 @@ This scaffolder requires the path to a Jenkins job config.xml file. config.xml i | Action | Description | | ------------------- | -------------------- | -| jenking:job:build | Run a job | -| jenking:job:copy | Copy an existing job | +| jenkins:job:build | Run a job | +| jenkins:job:copy | Copy an existing job | | jenkins:job:create | Create a job | | jenkins:job:destroy | Destroy a job | | jenkins:job:disable | Disable a job | @@ -93,10 +93,10 @@ Below, there is an example for each action name: Jenkins Job Build action: jenkins:job:build input: - jobName: first-job - jobParameters: - parameters: - PARAM1: value1 + jobName: first-job + jobParameters: + parameters: + PARAM1: value1 ``` - Copy job @@ -186,14 +186,11 @@ Below, there is an example for each action jobName: first-job ``` -- Enable job - **Action input parameters** - | Action | Description | - | --------------- | ---------------------------------------------- | - | _jobName_ | Name of job | - | _jobParameters_ | optional job parameters (object) to execute it | + | Action | Description | + | --------- | ----------- | + | _jobName_ | Name of job | ```yaml - id: jenkins-job-enable diff --git a/workspaces/jenkins/plugins/scaffolder-backend-module-jenkins/src/actions/job/build.ts b/workspaces/jenkins/plugins/scaffolder-backend-module-jenkins/src/actions/job/build.ts index d6e019fec4..08fb37a0f3 100644 --- a/workspaces/jenkins/plugins/scaffolder-backend-module-jenkins/src/actions/job/build.ts +++ b/workspaces/jenkins/plugins/scaffolder-backend-module-jenkins/src/actions/job/build.ts @@ -13,8 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + import { createTemplateAction } from '@backstage/plugin-scaffolder-node'; import Jenkins from 'jenkins'; +// Assuming 'z' for zod comes implicitly from createTemplateAction context + /** * * This buildJob function, creates a template action for running a Jenkins job @@ -25,20 +28,30 @@ import Jenkins from 'jenkins'; export function buildJob(jenkins: Jenkins) { return createTemplateAction({ id: 'jenkins:job:build', - description: 'Run an existing Jenkins job given its name', + description: + 'Run an existing Jenkins job given its name, optionally with parameters.', schema: { - input: z => - z.object({ - jobName: z.string().describe('Name of the Jenkins job to run'), - jobParameters: z.record(z.any()).optional(), - delay: z.number().optional(), - token: z.string().optional(), - }), + input: { + jobName: z => + z.string({ description: 'Name of the Jenkins job to run' }), + jobParameters: z => + z + .record(z.string(), z.any()) + .describe( + 'Optional parameters for the Jenkins job (key-value pairs)', + ) + .optional(), + }, }, async handler(ctx) { ctx.logger.info(`Starting Jenkins job: ${ctx.input.jobName}`); - await jenkins.job.build(ctx.input.jobName, ctx.input.jobParameters); + + const options = ctx.input.jobParameters + ? { parameters: ctx.input.jobParameters } + : undefined; + + await jenkins.job.build(ctx.input.jobName, options); ctx.logger.info('Job started successfully!'); }, });