Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions workspaces/jenkins/.changeset/humble-hounds-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@backstage-community/plugin-scaffolder-backend-module-jenkins': major
---

fix(jenkins): Correct buildJob parameter passing & enableJob description
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -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
Expand Down Expand Up @@ -184,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need zod added here?

Copy link
Author

@Ayushmore1214 Ayushmore1214 Oct 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good point! Since the schema was already using that z => ... syntax (which comes from Zod), I added it as an explicit dependency just to be safe and maybe make things easier if the schema needs more complex stuff later. But definitely happy to remove it if you prefer

},
"devDependencies": {
"@backstage/cli": "backstage:^"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 The Backstage Authors
* Copyright 2025 The Backstage Authors
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't update these dates, the idea is they reflect when this code was added. 👍

*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,8 +13,10 @@
* 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

/**
*
Expand All @@ -26,17 +28,30 @@ import Jenkins from 'jenkins';
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, optionally with parameters.',
schema: {
input: {
jobName: z => z.string({ description: 'Name of jenkins item' }),
jobParameters: z => z.record(z.any()).optional(),
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep existing whitespace and avoid making changes that aren't needed for the task at hand. 👍

ctx.logger.info(`Starting jenkins job ${ctx.input.jobName}`);
ctx.logger.info(`Starting Jenkins job: ${ctx.input.jobName}`);

const options = ctx.input.jobParameters
? { parameters: ctx.input.jobParameters }
: undefined;

await jenkins.job.build(ctx.input.jobName, ctx.input.jobParameters);
await jenkins.job.build(ctx.input.jobName, options);
ctx.logger.info('Job started successfully!');
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' }),
Expand Down
8 changes: 8 additions & 0 deletions workspaces/jenkins/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand Down