screwdriver-api 8.0.41 → 8.0.43

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": "8.0.41",
3
+ "version": "8.0.43",
4
4
  "description": "API server for the Screwdriver.cd service",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -5,6 +5,7 @@ const hoek = require('@hapi/hoek');
5
5
  const merge = require('lodash.mergewith');
6
6
  const { PR_JOB_NAME, PR_STAGE_NAME, STAGE_TEARDOWN_PATTERN } = require('screwdriver-data-schema').config.regex;
7
7
  const { getFullStageJobName } = require('../../helper');
8
+ const { updateVirtualBuildSuccess } = require('../triggers/helpers');
8
9
  const TERMINAL_STATUSES = ['FAILURE', 'ABORTED', 'UNSTABLE', 'COLLAPSED'];
9
10
  const FINISHED_STATUSES = ['FAILURE', 'SUCCESS', 'ABORTED', 'UNSTABLE', 'COLLAPSED'];
10
11
 
@@ -381,12 +382,18 @@ async function updateBuildAndTriggerDownstreamJobs(config, build, server, userna
381
382
  const stageIsDone = isStageDone(stageJobBuilds);
382
383
 
383
384
  if (stageIsDone) {
384
- stageTeardownBuild.status = 'QUEUED';
385
+ const teardownNode = newEvent.workflowGraph.nodes.find(n => n.id === stageTeardownJob.id);
386
+
385
387
  stageTeardownBuild.parentBuildId = stageJobBuilds.map(b => b.id);
386
388
 
387
- // TODO: Handle if a teardown job is virtual
388
- await stageTeardownBuild.update();
389
- await stageTeardownBuild.start();
389
+ if (teardownNode && teardownNode.virtual) {
390
+ await updateVirtualBuildSuccess(stageTeardownBuild);
391
+ } else {
392
+ stageTeardownBuild.status = 'QUEUED';
393
+
394
+ await stageTeardownBuild.update();
395
+ await stageTeardownBuild.start();
396
+ }
390
397
  }
391
398
  }
392
399
  }
@@ -606,6 +606,21 @@ async function getParentBuildStatus({ joinListNames, joinBuilds }) {
606
606
  return { hasFailure, done };
607
607
  }
608
608
 
609
+ /**
610
+ * Update virtual build status to SUCCESS and init metadata
611
+ * @param {Build} build
612
+ * @returns {Promise<Build>}
613
+ */
614
+ async function updateVirtualBuildSuccess(build) {
615
+ build.status = Status.SUCCESS;
616
+ build.statusMessage = BUILD_STATUS_MESSAGES.SKIP_VIRTUAL_JOB.statusMessage;
617
+ build.statusMessageType = BUILD_STATUS_MESSAGES.SKIP_VIRTUAL_JOB.statusMessageType;
618
+
619
+ await build.initMeta();
620
+
621
+ return build.update();
622
+ }
623
+
609
624
  /**
610
625
  * Handle new build logic: update, start, or remove
611
626
  * If the build is done, check if it has a failure:
@@ -668,27 +683,11 @@ async function handleNewBuild({
668
683
  /* Prepare to execute the build */
669
684
  const parentBuilds = Object.values(joinBuilds);
670
685
 
671
- parentBuilds.sort((l, r) => {
672
- if (l.endTime && r.endTime) {
673
- return l.endTime.getTime() - r.endTime.getTime();
674
- }
675
-
676
- // Move to tail if endTime is not set
677
- return (l.endTime ? 0 : 1) - (r.endTime ? 0 : 1);
678
- });
679
686
  newBuild.parentBuildId = parentBuilds.map(build => build.id);
680
687
 
681
688
  // Bypass execution of the build if the job is virtual
682
689
  if (isVirtualJob && !hasFreezeWindows(job)) {
683
- newBuild.status = Status.SUCCESS;
684
- newBuild.statusMessage = BUILD_STATUS_MESSAGES.SKIP_VIRTUAL_JOB.statusMessage;
685
- newBuild.statusMessageType = BUILD_STATUS_MESSAGES.SKIP_VIRTUAL_JOB.statusMessageType;
686
-
687
- // The virtual job does not inherit metadata because the Launcher is not executed.
688
- // Therefore, it is necessary to take over the metadata from the previous build.
689
- newBuild.meta = parentBuilds.reduce((acc, build) => merge(acc, build.meta), {});
690
-
691
- return newBuild.update();
690
+ return updateVirtualBuildSuccess(newBuild);
692
691
  }
693
692
 
694
693
  // All join builds finished successfully, and it's clear that a new build has not been started before.
@@ -1220,5 +1219,6 @@ module.exports = {
1220
1219
  isStartFromMiddleOfCurrentStage,
1221
1220
  hasFreezeWindows,
1222
1221
  getNextJobStageName,
1222
+ updateVirtualBuildSuccess,
1223
1223
  BUILD_STATUS_MESSAGES
1224
1224
  };
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const merge = require('lodash.mergewith');
4
- const { createInternalBuild, Status, BUILD_STATUS_MESSAGES, hasFreezeWindows } = require('./helpers');
3
+ const { createInternalBuild, Status, updateVirtualBuildSuccess, hasFreezeWindows } = require('./helpers');
5
4
 
6
5
  /**
7
6
  * @typedef {import('screwdriver-models').BuildFactory} BuildFactory
@@ -60,14 +59,7 @@ class OrBase {
60
59
 
61
60
  // Bypass execution of the build if the job is virtual
62
61
  if (isNextJobVirtual && !hasWindows) {
63
- nextBuild.status = Status.SUCCESS;
64
- nextBuild.statusMessage = BUILD_STATUS_MESSAGES.SKIP_VIRTUAL_JOB.statusMessage;
65
- nextBuild.statusMessageType = BUILD_STATUS_MESSAGES.SKIP_VIRTUAL_JOB.statusMessageType;
66
-
67
- // Overwrite metadata by current build's
68
- nextBuild.meta = merge({}, this.currentBuild.meta);
69
-
70
- return nextBuild.update();
62
+ return updateVirtualBuildSuccess(nextBuild);
71
63
  }
72
64
 
73
65
  nextBuild.status = Status.QUEUED;
@@ -94,14 +86,7 @@ class OrBase {
94
86
 
95
87
  // Bypass execution of the build if the job is virtual
96
88
  if (isNextJobVirtual && !hasWindows) {
97
- nextBuild.status = Status.SUCCESS;
98
- nextBuild.statusMessage = BUILD_STATUS_MESSAGES.SKIP_VIRTUAL_JOB.statusMessage;
99
- nextBuild.statusMessageType = BUILD_STATUS_MESSAGES.SKIP_VIRTUAL_JOB.statusMessageType;
100
-
101
- // Overwrite metadata by current build's
102
- nextBuild.meta = merge({}, this.currentBuild.meta);
103
-
104
- await nextBuild.update();
89
+ await updateVirtualBuildSuccess(nextBuild);
105
90
  }
106
91
 
107
92
  return nextBuild;