From ce74e4a6ba12ab818e189ff3a2f177433cb75268 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Thu, 17 Sep 2026 10:32:50 +0200 Subject: [PATCH] fix: start CI when the duplicate check cannot query Jenkins Signed-off-by: Matteo Collina --- lib/ci/run_ci.js | 18 ++++++++++++++---- test/unit/ci_start.test.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/lib/ci/run_ci.js b/lib/ci/run_ci.js index 30331766..7963849f 100644 --- a/lib/ci/run_ci.js +++ b/lib/ci/run_ci.js @@ -94,10 +94,20 @@ export class RunPRJob { if (checkForDuplicates) { await this.prData.getComments(); const { jobid, link } = new JobParser(this.prData.comments).parse().get('PR') ?? {}; - const { actions } = jobid - ? (await new PRBuild(cli, request, jobid, undefined, 'actions[parameters[name,value]]') - .getBuildData()) - : {}; + let actions; + try { + ({ actions } = jobid + ? (await new PRBuild(cli, request, jobid, undefined, 'actions[parameters[name,value]]') + .getBuildData()) + : {}); + } catch (err) { + // Jenkins may no longer have the build (e.g. the record was lost) or + // may answer with an HTML error page instead of JSON. Do not let that + // block starting a new CI run. + cli.stopSpinner(`Could not query existing CI run ${link}: ${err.message}`, + cli.SPINNER_STATUS.WARN); + cli.warn('Skipping the duplicate CI check'); + } const { parameters } = actions?.find(a => 'parameters' in a) ?? {}; if (parameters?.find(c => c.name === 'COMMIT_SHA_CHECK')?.value === certifySafe) { cli.info('Existing CI run found: ' + link); diff --git a/test/unit/ci_start.test.js b/test/unit/ci_start.test.js index b2199288..7266ec78 100644 --- a/test/unit/ci_start.test.js +++ b/test/unit/ci_start.test.js @@ -335,5 +335,33 @@ describe('Jenkins', () => { const jobRunner = new RunPRJob(cli, request, owner, repo, prid, 'deadbeef', true); assert.strictEqual(await jobRunner.start(), true); }); + it('should start CI when the existing CI run cannot be queried', async() => { + const cli = new TestCLI(); + const err = new SyntaxError('Unexpected token \'<\', " { + assert.strictEqual(url, CI_PR_URL); + assert.strictEqual(method, 'POST'); + assert.deepStrictEqual(headers, { 'Jenkins-Crumb': crumb }); + return Promise.resolve({ status: 201 }); + }), + json: sinon.stub().withArgs(CI_CRUMB_URL).resolves({ crumb }) + }; + const jobRunner = new RunPRJob(cli, request, owner, repo, prid, 'deadbeef', true); + assert.strictEqual(await jobRunner.start(), true); + assert.strictEqual(request.fetch.callCount, 1); + }); }); });