screwdriver-api 6.0.40 → 6.0.41

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.40",
3
+ "version": "6.0.41",
4
4
  "description": "API server for the Screwdriver.cd service",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -528,29 +528,27 @@ 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
- return null;
533
- }
534
- if (!['CREATED', null, undefined].includes(newBuild.status)) {
535
- return null;
536
- }
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
+ }
537
541
 
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();
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();
544
546
 
545
- return null;
547
+ return queuedBuild.start();
548
+ }
546
549
  }
547
550
 
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();
551
+ return null;
554
552
  }
555
553
 
556
554
  /**
@@ -832,29 +830,18 @@ const buildsPlugin = {
832
830
  parentBuilds,
833
831
  parentBuildId: current.build.id
834
832
  };
833
+ let newBuild;
835
834
 
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);
848
- }
849
-
850
- if (!['CREATED', null, undefined].includes(existNextBuild.status)) {
851
- return existNextBuild;
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
+ );
852
842
  }
853
843
 
854
- existNextBuild.status = 'QUEUED';
855
- await existNextBuild.update();
856
-
857
- return existNextBuild.start();
844
+ return newBuild;
858
845
  }
859
846
 
860
847
  logger.info(`Fetching finished builds for event ${event.id}`);