From 78f6fdd44ce530d3f919068c843453b45a42eb0f Mon Sep 17 00:00:00 2001 From: sadarunnisa-sf Date: Wed, 25 Dec 2024 02:52:07 +0530 Subject: [PATCH 1/3] feat(plugins): jenkins plugin implemented jenkins plugin implemented ARC-101 --- .../src/service/jenkinsApi.ts | 66 +++++++++---------- 1 file changed, 30 insertions(+), 36 deletions(-) diff --git a/plugins/jenkins-with-reporting-backend-backend/src/service/jenkinsApi.ts b/plugins/jenkins-with-reporting-backend-backend/src/service/jenkinsApi.ts index ae8f335..7d85f2c 100644 --- a/plugins/jenkins-with-reporting-backend-backend/src/service/jenkinsApi.ts +++ b/plugins/jenkins-with-reporting-backend-backend/src/service/jenkinsApi.ts @@ -84,56 +84,50 @@ export class JenkinsApiImpl { */ async getProjects(jenkinsInfo: JenkinsInfo, branches?: string[]) { const client = await JenkinsApiImpl.getClient(jenkinsInfo); - const projects: BackstageProject[] = []; + const projects = []; + const treeSpec = JenkinsApiImpl.jobsTreeSpec; if (branches) { - // Assume jenkinsInfo.jobFullName is a MultiBranch Pipeline project which contains one job per branch. - const job = await Promise.any( branches.map(branch => client.job.get({ name: `${jenkinsInfo.jobFullName}/${encodeURIComponent(branch)}`, - tree: JenkinsApiImpl.jobTreeSpec.replace(/\s/g, ''), - }), - ), + tree: JenkinsApiImpl.jobTreeSpec.replace(/\s/g, ""), + }) + ) ); projects.push(this.augmentProject(job)); } else { - // We aren't filtering - // Assume jenkinsInfo.jobFullName is either - // a MultiBranch Pipeline (folder with one job per branch) project - // a Pipeline (standalone) project - - // Add count limit to projects - // If limit is set in the config, use it, otherwise use the default limit of 50 - const limitedJobsTreeSpec: string = `${JenkinsApiImpl.jobsTreeSpec}{0,${jenkinsInfo.projectCountLimit}}`; //NOSONAR - - const project = await client.job.get({ - name: jenkinsInfo.jobFullName, - // Filter only be the information we need, instead of loading all fields. - // Whitespaces are only included for readability here and stripped out - // before sending to Jenkins - tree: limitedJobsTreeSpec.replace(/\s/g, ''), - }); - - const isStandaloneProject = !project.jobs; - if (isStandaloneProject) { - const limitedStandaloneJobTreeSpec = `${JenkinsApiImpl.jobTreeSpec}{0,${jenkinsInfo.projectCountLimit}}`; - const standaloneProject = await client.job.get({ - name: jenkinsInfo.jobFullName, - tree: limitedStandaloneJobTreeSpec.replace(/\s/g, ''), - }); - projects.push(this.augmentProject(standaloneProject)); - return projects; - } - for (const jobDetails of project.jobs) { - // for each branch (we assume) - projects.push(this.augmentProject(jobDetails)); + const rootProjects = await this.getNestedJobs(client, jenkinsInfo.jobFullName, treeSpec); + projects.push(...rootProjects); + } + + return projects; + } + + async getNestedJobs(client:any, jobName : string, treeSpec: string):Promise { + const project = await client.job.get({ + name: jobName, + tree: treeSpec.replace(/\s/g, ""), + }); + + const projects = []; + if (project.jobs) { + for (const subJob of project.jobs) { + if (subJob._class === 'com.cloudbees.hudson.plugins.folder.Folder') { + const nestedProjects = await this.getNestedJobs(client, subJob.fullName, treeSpec); + projects.push(...nestedProjects); + } else { + projects.push(this.augmentProject(subJob)); + } } + } else { + projects.push(this.augmentProject(project)); } return projects; } + /** * Get a single build. * @see ../../../jenkins/src/api/JenkinsApi.ts#getBuild From 3f0a99b6aa4f1dacf47f9ba433abcfac36057d43 Mon Sep 17 00:00:00 2001 From: sadarunnisa-sf Date: Wed, 25 Dec 2024 03:06:01 +0530 Subject: [PATCH 2/3] feat(plugins): jenkins plugin implemented jenkins plugin implemented ARC-101 --- .../src/service/jenkinsApi.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/plugins/jenkins-with-reporting-backend-backend/src/service/jenkinsApi.ts b/plugins/jenkins-with-reporting-backend-backend/src/service/jenkinsApi.ts index 7d85f2c..f5785b8 100644 --- a/plugins/jenkins-with-reporting-backend-backend/src/service/jenkinsApi.ts +++ b/plugins/jenkins-with-reporting-backend-backend/src/service/jenkinsApi.ts @@ -96,10 +96,12 @@ export class JenkinsApiImpl { }) ) ); - projects.push(this.augmentProject(job)); + // @ts-ignore + projects.push(this.augmentProject(job)); //NOSONAR } else { const rootProjects = await this.getNestedJobs(client, jenkinsInfo.jobFullName, treeSpec); - projects.push(...rootProjects); + // @ts-ignore + projects.push(...rootProjects); //NOSONAR } return projects; @@ -116,13 +118,16 @@ export class JenkinsApiImpl { for (const subJob of project.jobs) { if (subJob._class === 'com.cloudbees.hudson.plugins.folder.Folder') { const nestedProjects = await this.getNestedJobs(client, subJob.fullName, treeSpec); - projects.push(...nestedProjects); + // @ts-ignore + projects.push(...nestedProjects); //NOSONAR } else { - projects.push(this.augmentProject(subJob)); + // @ts-ignore + projects.push(this.augmentProject(subJob)); //NOSONAR } } } else { - projects.push(this.augmentProject(project)); + // @ts-ignore + projects.push(this.augmentProject(project)); //NOSONAR } return projects; } From 6ea42311ad74f1f37310182705763c6f5464d798 Mon Sep 17 00:00:00 2001 From: sadarunnisa-sf Date: Wed, 25 Dec 2024 03:10:18 +0530 Subject: [PATCH 3/3] feat(plugins): jenkins plugin implemented jenkins plugin implemented ARC-101 --- .../src/service/jenkinsApi.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/jenkins-with-reporting-backend-backend/src/service/jenkinsApi.ts b/plugins/jenkins-with-reporting-backend-backend/src/service/jenkinsApi.ts index f5785b8..f17cf85 100644 --- a/plugins/jenkins-with-reporting-backend-backend/src/service/jenkinsApi.ts +++ b/plugins/jenkins-with-reporting-backend-backend/src/service/jenkinsApi.ts @@ -107,7 +107,7 @@ export class JenkinsApiImpl { return projects; } - async getNestedJobs(client:any, jobName : string, treeSpec: string):Promise { + async getNestedJobs(client:any, jobName : string, treeSpec: string):Promise { //NOSONAR const project = await client.job.get({ name: jobName, tree: treeSpec.replace(/\s/g, ""),