Skip to content

feat(jenkins): support jobs across multiple instances - #10769

Open
alvaroc20 wants to merge 2 commits into
backstage:mainfrom
alvaroc20:jenkins-multi-instance-jobs
Open

alvaroc20 wants to merge 2 commits into
backstage:mainfrom
alvaroc20:jenkins-multi-instance-jobs

Conversation

@alvaroc20

Copy link
Copy Markdown

Hey, I just made a Pull Request!

This allows a single catalog entity to reference jobs from multiple named Jenkins instances.

Jobs are scoped by both instance name and full job name, so identically named jobs on different instances do not collide. Unprefixed jobs continue to resolve through the default instance, preserving existing single-instance behavior.

The originating instance is retained when listing builds, opening build details, viewing history and logs, or retrying a build.

Closes #10301

image

Validation

  • Backend tests: 40 passed
  • Frontend tests: 5 passed
  • Type checking, linting, formatting, and API report validation passed
  • Manually validated two named instances containing the same full job name

✔️ Checklist

  • A changeset describing the change and affected packages. (more info)
  • Added or updated documentation
  • Tests for new functionality and regression tests for bug fixes
  • Screenshots attached (for UI changes)
  • All your commits have a Signed-off-by line in the message. (more info)

@backstage-goalie

backstage-goalie Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Important

This PR includes changes that affect public-facing API. Please ensure you are adding/updating documentation for new features or behavior.

Changed Packages

Package Name Package Path Changeset Bump Current Version
@backstage-community/plugin-jenkins-backend workspaces/jenkins/plugins/jenkins-backend minor v0.32.0
@backstage-community/plugin-jenkins workspaces/jenkins/plugins/jenkins minor v0.35.0

@alvaroc20

Copy link
Copy Markdown
Author

Hi @vinzscam just a quick ping on this one 🙂

Let me know if there's anything I can change or add to help get it reviewed. Thanks you in advance!

}
throw err;
}
const projectsByInstance = await Promise.all(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

With Promise.all, a single unreachable instance hides results from the healthy ones. That's documented in the README, but would Promise.allSettled with per-instance errors make sense here?
Rough idea:

const results = await Promise.allSettled(jenkinsInstances.map(/* ... */));

plus an errors: [{ instanceName, message }] array for the rejected ones

...project,
instanceName: jenkinsInfo.instanceName,
}));
} catch (error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Previously only the AggregateError case was wrapped and other errors were rethrown as-is. Now every error becomes a plain Error, so typed errors (e.g. NotFoundError, NotAllowedError from @backstage/errors) turn into 500s. Could this use ForwardedError from @backstage/errors so the original status is kept?

return (
(await response.json()).projects?.map((p: Project) => ({
...p,
instanceName: p.instanceName ?? 'default',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

defaulting to 'default' on the client means every link/retry sends ?instanceName=default even when the backend didn't return one. It doesn't break anything, but leaving it undefined would let the backend's resolution logic decide.

@alvaroc20

Copy link
Copy Markdown
Author

Hi @Shubhammete

Thank you for your comments!

  • Promise.allSettled: Done. The projects endpoint now returns { projects, errors: [{ instanceName, message }] } and only fails when every instance fails, so single-instance entities behave as before. jenkins:list-builds returns the same errors, and the table shows a warning naming the failing instances. To surface them in the frontend I added an optional getProjectsWithErrors method to JenkinsApi; it’s optional so existing custom implementations keep working. While testing I also found that JenkinsClient never checked response.ok and silently returned an empty list on any backend error, so that’s fixed too.

  • ForwardedError: Agreed, switched to ForwardedError so the cause’s name, and with it the status, is kept. The AggregateError from the branch lookup is still unwrapped so its causes appear in the message. Added a test where a NotFoundError comes back as a 404.

  • Default instanceName: Removed. The client now leaves it undefined and lets the backend resolve it.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues require further changes.

No open issues 🎉

What changed in this PR

Extends the Jenkins frontend and backend so one catalog entity can reference jobs across multiple named instances, addressing #10301 while preserving single-instance compatibility.

Changes:

  • Groups jobs by instance and carries instance selection through API requests, navigation, and backend actions.
  • Returns partial results when some instances fail, with warnings and a conditional Instance column.
  • Adds regression tests, public API updates, documentation, examples, and release changesets.

Paths below are relative to workspaces/jenkins/.

File Description
plugins/​jenkins/​src/​components/​useJobRuns.ts Passes instance selection to history requests.
plugins/​jenkins/​src/​components/​useBuildWithSteps.ts Fetches builds by instance and catches request failures.
plugins/​jenkins/​src/​components/​useBuilds.ts Handles partial failures and instance-aware retries.
plugins/​jenkins/​src/​components/​JobRunsTable/​JobRunsTable.tsx Reads instance selection from the URL.
plugins/​jenkins/​src/​components/​BuildWithStepsPage/​BuildWithStepsPage.tsx Passes URL instance selection to build fetching.
plugins/​jenkins/​src/​components/​BuildsPage/​lib/​CITable/​presets.ts Adds the default Instance column.
plugins/​jenkins/​src/​components/​BuildsPage/​lib/​CITable/​columns.tsx Preserves instance selection in build and history links.
plugins/​jenkins/​src/​components/​BuildsPage/​lib/​CITable/​CITable.tsx Displays failure warnings and conditional instance labels.
plugins/​jenkins/​src/​components/​BuildsPage/​lib/​CITable/​CITable.test.tsx Tests instance columns, warnings, and build links.
plugins/​jenkins/​src/​api/​JenkinsApi.ts Adds instance-aware requests and partial-result handling.
plugins/​jenkins/​src/​api/​JenkinsApi.test.ts Tests request routing, retries, and error responses.
plugins/​jenkins/​src/​api/​index.ts Exports partial-result and instance-error types.
plugins/​jenkins/​report.api.md Records frontend public API additions.
plugins/​jenkins/​README.md Documents multi-instance usage and failure displays.
plugins/​jenkins-backend/​src/​service/​jenkinsInfoProvider.ts Resolves annotation jobs into instance-specific configurations.
plugins/​jenkins-backend/​src/​service/​jenkinsInfoProvider.test.ts Tests grouping, selection, and annotation validation.
plugins/​jenkins-backend/​src/​service/​JenkinsBuilder.ts Routes instance selectors and aggregates project results.
plugins/​jenkins-backend/​src/​service/​JenkinsBuilder.test.ts Tests routing, partial failures, and error preservation.
plugins/​jenkins-backend/​src/​service/​index.ts Exports provider options.
plugins/​jenkins-backend/​src/​service/​getProjectsFromInstances.ts Queries instances concurrently and collects failures.
plugins/​jenkins-backend/​src/​service/​getJenkinsInstances.ts Supports plural providers with a legacy fallback.
plugins/​jenkins-backend/​src/​actions/​createTriggerBuildAction.ts Accepts instance selection for triggering builds.
plugins/​jenkins-backend/​src/​actions/​createTriggerBuildAction.test.ts Verifies trigger instance forwarding.
plugins/​jenkins-backend/​src/​actions/​createListBuildsAction.ts Returns builds across instances with failure details.
plugins/​jenkins-backend/​src/​actions/​createListBuildsAction.test.ts Tests duplicate job names and partial results.
plugins/​jenkins-backend/​src/​actions/​createGetBuildLogsAction.ts Passes job and instance selection to the provider.
plugins/​jenkins-backend/​src/​actions/​createGetBuildLogsAction.test.ts Verifies log-request provider arguments.
plugins/​jenkins-backend/​src/​actions/​createGetBuildAction.ts Accepts instance selection for build details.
plugins/​jenkins-backend/​src/​actions/​createGetBuildAction.test.ts Verifies build-detail instance forwarding.
plugins/​jenkins-backend/​README.md Documents configuration, actions, failures, and custom providers.
examples/​entities.yaml Demonstrates jobs spanning default and named instances.
app-config.yaml Adds a named instance for the example.
.changeset/​calm-dragons-build.md Announces frontend and backend feature releases.

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

jenkins-backend: any way to support jobs from different named instances on the same entity?

4 participants