diff --git a/plugins/jenkins-backend/src/service/jenkinsApi.test.ts b/plugins/jenkins-backend/src/service/jenkinsApi.test.ts index 4f65e446fd..8413cc6699 100644 --- a/plugins/jenkins-backend/src/service/jenkinsApi.test.ts +++ b/plugins/jenkins-backend/src/service/jenkinsApi.test.ts @@ -75,6 +75,37 @@ describe('JenkinsApi', () => { }, }; + describe('standalone project', () => { + it('should return the only build', async () => { + mockedJenkinsClient.job.get + .mockResolvedValueOnce(project) + .mockResolvedValueOnce(project); + const result = await jenkinsApi.getProjects(jenkinsInfo); + expect(result).toHaveLength(1); + expect(result[0]).toEqual({ + actions: [], + displayName: 'Example Build', + fullDisplayName: 'Example jobName » Example Build', + fullName: 'example-jobName/exampleBuild', + inQueue: false, + lastBuild: { + actions: [], + timestamp: 1, + building: false, + duration: 10, + result: 'success', + displayName: '#7', + fullDisplayName: 'Example jobName » Example Build #7', + url: 'https://jenkins.example.com/job/example-jobName/job/exampleBuild', + number: 7, + status: 'success', + source: {}, + }, + status: 'success', + }); + }); + }); + describe('unfiltered', () => { it('standard github layout', async () => { mockedJenkinsClient.job.get.mockResolvedValueOnce({ jobs: [project] }); diff --git a/plugins/jenkins-backend/src/service/jenkinsApi.ts b/plugins/jenkins-backend/src/service/jenkinsApi.ts index 89c9a41f9c..be8fe1b983 100644 --- a/plugins/jenkins-backend/src/service/jenkinsApi.ts +++ b/plugins/jenkins-backend/src/service/jenkinsApi.ts @@ -89,7 +89,7 @@ export class JenkinsApiImpl { } else { // We aren't filtering // Assume jenkinsInfo.jobFullName is a folder which contains one job per branch. - const folder = await client.job.get({ + const project = await client.job.get({ name: jenkinsInfo.jobFullName, // Filter only be the information we need, instead of loading all fields. // Limit to only show the latest build for each job and only load 50 jobs @@ -99,8 +99,16 @@ export class JenkinsApiImpl { tree: JenkinsApiImpl.jobsTreeSpec.replace(/\s/g, ''), }); - // TODO: support this being a project itself. - for (const jobDetails of folder.jobs) { + const isStandaloneProject = !project.jobs; + if (isStandaloneProject) { + const standaloneProject = await client.job.get({ + name: jenkinsInfo.jobFullName, + tree: JenkinsApiImpl.jobTreeSpec.replace(/\s/g, ''), + }); + projects.push(this.augmentProject(standaloneProject)); + return projects; + } + for (const jobDetails of project.jobs) { // for each branch (we assume) if (jobDetails?.jobs) { // skipping folders inside folders for now