screwdriver-api 6.0.39 → 6.0.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "screwdriver-api",
3
- "version": "6.0.39",
3
+ "version": "6.0.40",
4
4
  "description": "API server for the Screwdriver.cd service",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -528,27 +528,29 @@ async function getParentBuildStatus({ newBuild, joinListNames, pipelineId, build
528
528
  * @return {Promise} The newly updated/created build
529
529
  */
530
530
  async function handleNewBuild({ done, hasFailure, newBuild, jobName, pipelineId }) {
531
- if (done) {
532
- // Delete new build since previous build failed
533
- if (hasFailure) {
534
- logger.info(
535
- `Failure occurred in upstream job, removing new build - build:${newBuild.id} pipeline:${pipelineId}-${jobName} event:${newBuild.eventId} `
536
- );
537
- await newBuild.remove();
538
-
539
- return null;
540
- }
531
+ if (!done) {
532
+ return null;
533
+ }
534
+ if (!['CREATED', null, undefined].includes(newBuild.status)) {
535
+ return null;
536
+ }
541
537
 
542
- // If all join builds finished successfully and it's clear that a new build has not been started before, start new build
543
- if (['CREATED', null, undefined].includes(newBuild.status)) {
544
- newBuild.status = 'QUEUED';
545
- const queuedBuild = await newBuild.update();
538
+ // Delete new build since previous build failed
539
+ if (hasFailure) {
540
+ logger.info(
541
+ `Failure occurred in upstream job, removing new build - build:${newBuild.id} pipeline:${pipelineId}-${jobName} event:${newBuild.eventId} `
542
+ );
543
+ await newBuild.remove();
546
544
 
547
- return queuedBuild.start();
548
- }
545
+ return null;
549
546
  }
550
547
 
551
- return null;
548
+ // All join builds finished successfully and it's clear that a new build has not been started before.
549
+ // Start new build.
550
+ newBuild.status = 'QUEUED';
551
+ await newBuild.update();
552
+
553
+ return newBuild.start();
552
554
  }
553
555
 
554
556
  /**
@@ -830,18 +832,29 @@ const buildsPlugin = {
830
832
  parentBuilds,
831
833
  parentBuildId: current.build.id
832
834
  };
833
- let newBuild;
834
835
 
835
- try {
836
- newBuild = await createInternalBuild(internalBuildConfig);
837
- } catch (err) {
838
- logger.error(
839
- `Error in triggerNextJobs - pipeline:${current.pipeline.id}-${nextJobName} event:${event.id} `,
840
- err
841
- );
836
+ const nextJob = await jobFactory.get({
837
+ name: nextJobName,
838
+ pipelineId: current.pipeline.id
839
+ });
840
+
841
+ const existNextBuild = await buildFactory.get({
842
+ eventId: current.event.id,
843
+ jobId: nextJob.id
844
+ });
845
+
846
+ if (existNextBuild === null) {
847
+ return createInternalBuild(internalBuildConfig);
842
848
  }
843
849
 
844
- return newBuild;
850
+ if (!['CREATED', null, undefined].includes(existNextBuild.status)) {
851
+ return existNextBuild;
852
+ }
853
+
854
+ existNextBuild.status = 'QUEUED';
855
+ await existNextBuild.update();
856
+
857
+ return existNextBuild.start();
845
858
  }
846
859
 
847
860
  logger.info(`Fetching finished builds for event ${event.id}`);