screwdriver-api 8.0.114 → 8.0.116

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.114",
3
+ "version": "8.0.116",
4
4
  "description": "API server for the Screwdriver.cd service",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -139,6 +139,17 @@ function hasFreezeWindows(job) {
139
139
  return freezeWindows ? freezeWindows.length > 0 : false;
140
140
  }
141
141
 
142
+ /**
143
+ * Checks if job has blockedBy
144
+ * @param {Job} job Job object
145
+ * @returns {Boolean}
146
+ */
147
+ function hasBlockedBy(job) {
148
+ const { blockedBy } = job.permutations[0];
149
+
150
+ return blockedBy ? blockedBy.length > 0 : false;
151
+ }
152
+
142
153
  /**
143
154
  * Get external pipelineId and job name from the `name`
144
155
  * @param {String} name Job name
@@ -771,7 +782,7 @@ async function handleNewBuild({
771
782
  newBuild.parentBuildId = parentBuilds.map(build => build.id);
772
783
 
773
784
  // Bypass execution of the build if the job is virtual
774
- if (isVirtualJob && !hasFreezeWindows(job)) {
785
+ if (isVirtualJob && !hasFreezeWindows(job) && !hasBlockedBy(job)) {
775
786
  return updateVirtualBuildSuccess({ server, build: newBuild, event, job });
776
787
  }
777
788
 
@@ -1310,6 +1321,7 @@ module.exports = {
1310
1321
  trimJobName,
1311
1322
  isStartFromMiddleOfCurrentStage,
1312
1323
  hasFreezeWindows,
1324
+ hasBlockedBy,
1313
1325
  getNextJobStageName,
1314
1326
  updateVirtualBuildSuccess,
1315
1327
  BUILD_STATUS_MESSAGES
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const { createInternalBuild, Status, updateVirtualBuildSuccess, hasFreezeWindows } = require('./helpers');
3
+ const { createInternalBuild, Status, updateVirtualBuildSuccess, hasFreezeWindows, hasBlockedBy } = require('./helpers');
4
4
 
5
5
  /**
6
6
  * @typedef {import('screwdriver-models').BuildFactory} BuildFactory
@@ -49,6 +49,7 @@ class OrBase {
49
49
  });
50
50
 
51
51
  const hasWindows = hasFreezeWindows(nextJob);
52
+ const hasBlocked = hasBlockedBy(nextJob);
52
53
  const causeMessage = nextJob.name === event.startFrom ? event.causeMessage : '';
53
54
 
54
55
  if (nextBuild !== null) {
@@ -59,7 +60,7 @@ class OrBase {
59
60
  nextBuild.parentBuildId = [this.currentBuild.id];
60
61
 
61
62
  // Bypass execution of the build if the job is virtual
62
- if (isNextJobVirtual && !hasWindows) {
63
+ if (isNextJobVirtual && !hasWindows && !hasBlocked) {
63
64
  return updateVirtualBuildSuccess({ server: this.server, build: nextBuild, event, job: nextJob });
64
65
  }
65
66
 
@@ -81,12 +82,12 @@ class OrBase {
81
82
  baseBranch: event.baseBranch || null,
82
83
  parentBuilds,
83
84
  parentBuildId: this.currentBuild.id,
84
- start: hasWindows || !isNextJobVirtual,
85
+ start: hasBlocked || hasWindows || !isNextJobVirtual,
85
86
  causeMessage
86
87
  });
87
88
 
88
89
  // Bypass execution of the build if the job is virtual
89
- if (isNextJobVirtual && !hasWindows) {
90
+ if (isNextJobVirtual && !hasWindows && !hasBlocked) {
90
91
  await updateVirtualBuildSuccess({ server: this.server, build: nextBuild, event, job: nextJob });
91
92
  }
92
93
 
@@ -21,7 +21,19 @@ function getVirtualJobIds(virtualNodeNames, prJobs) {
21
21
  const prJobName = prJob.name.match(PR_JOB_NAME);
22
22
  const nodeName = prJobName ? prJobName[2] : prJob.name;
23
23
 
24
+ // if prJob has blockedBy or freezeWindows annotation
25
+ // then it needs to be queued for scheduling
24
26
  if (virtualNodeNames.includes(nodeName)) {
27
+ const permutations = prJob.permutations || [];
28
+ const hasBlockedBy = permutations[0] && permutations[0].blockedBy;
29
+ const hasFreezeWindows = permutations[0] && permutations[0].freezeWindows;
30
+
31
+ const needsScheduling = Boolean(hasBlockedBy || hasFreezeWindows);
32
+
33
+ if (needsScheduling) {
34
+ return;
35
+ }
36
+
25
37
  virtualJobIds.push(prJob.id);
26
38
  }
27
39
  });