screwdriver-api 8.0.8 → 8.0.10

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.8",
3
+ "version": "8.0.10",
4
4
  "description": "API server for the Screwdriver.cd service",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -111,7 +111,7 @@
111
111
  "screwdriver-config-parser": "^12.0.0",
112
112
  "screwdriver-coverage-bookend": "^3.0.0",
113
113
  "screwdriver-coverage-sonar": "^5.0.0",
114
- "screwdriver-data-schema": "^25.1.0",
114
+ "screwdriver-data-schema": "^25.1.3",
115
115
  "screwdriver-datastore-sequelize": "^10.0.0",
116
116
  "screwdriver-executor-base": "^11.0.0",
117
117
  "screwdriver-executor-docker": "^8.0.1",
@@ -39,8 +39,7 @@ const {
39
39
  getParallelBuilds,
40
40
  isStartFromMiddleOfCurrentStage,
41
41
  Status,
42
- getSameParentEvents,
43
- isVirtualJob
42
+ getSameParentEvents
44
43
  } = require('./triggers/helpers');
45
44
  const { getFullStageJobName } = require('../helper');
46
45
 
@@ -96,9 +95,11 @@ async function triggerNextJobs(config, app) {
96
95
 
97
96
  const downstreamOfNextJobsToBeProcessed = [];
98
97
 
99
- for (const [nextJobName, nextJobInfo] of Object.entries(currentPipelineNextJobs)) {
98
+ for (const [nextJobName] of Object.entries(currentPipelineNextJobs)) {
100
99
  const nextJob = await getJob(nextJobName, currentPipeline.id, jobFactory);
101
- const { stageName: nextJobStageName } = nextJobInfo;
100
+ const node = currentEvent.workflowGraph.nodes.find(n => n.name === trimJobName(nextJobName));
101
+ const isNextJobVirtual = node.virtual || false;
102
+ const nextJobStageName = node.stageName || null;
102
103
  const resource = `pipeline:${currentPipeline.id}:groupEvent:${currentEvent.groupEventId}`;
103
104
  let lock;
104
105
  let nextBuild;
@@ -124,12 +125,24 @@ async function triggerNextJobs(config, app) {
124
125
  isOrTrigger(currentEvent.workflowGraph, originalCurrentJobName, trimJobName(nextJobName)) ||
125
126
  isStartFromMiddleOfCurrentStage(currentJob.name, currentEvent.startFrom, currentEvent.workflowGraph)
126
127
  ) {
127
- nextBuild = await orTrigger.execute(currentEvent, currentPipeline.id, nextJob, parentBuilds);
128
+ nextBuild = await orTrigger.execute(
129
+ currentEvent,
130
+ currentPipeline.id,
131
+ nextJob,
132
+ parentBuilds,
133
+ isNextJobVirtual
134
+ );
128
135
  } else {
129
- nextBuild = await andTrigger.execute(nextJob, parentBuilds, joinListNames, nextJobStageName);
136
+ nextBuild = await andTrigger.execute(
137
+ nextJob,
138
+ parentBuilds,
139
+ joinListNames,
140
+ isNextJobVirtual,
141
+ nextJobStageName
142
+ );
130
143
  }
131
144
 
132
- if (isVirtualJob(nextJob) && nextBuild && nextBuild.status === Status.SUCCESS) {
145
+ if (isNextJobVirtual && nextBuild && nextBuild.status === Status.SUCCESS) {
133
146
  downstreamOfNextJobsToBeProcessed.push({
134
147
  build: nextBuild,
135
148
  event: currentEvent,
@@ -274,7 +287,9 @@ async function triggerNextJobs(config, app) {
274
287
  if (externalEvent) {
275
288
  for (const [nextJobName, nextJobInfo] of Object.entries(joinedPipeline.jobs)) {
276
289
  const nextJob = await getJob(nextJobName, joinedPipelineId, jobFactory);
277
- const { stageName: nextJobStageName } = nextJobInfo;
290
+ const node = externalEvent.workflowGraph.nodes.find(n => n.name === trimJobName(nextJobName));
291
+ const isNextJobVirtual = node.virtual || false;
292
+ const nextJobStageName = node.stageName || null;
278
293
 
279
294
  const { parentBuilds } = parseJobInfo({
280
295
  joinObj: joinedPipeline.jobs,
@@ -295,7 +310,8 @@ async function triggerNextJobs(config, app) {
295
310
  externalEvent,
296
311
  externalEvent.pipelineId,
297
312
  nextJob,
298
- parentBuilds
313
+ parentBuilds,
314
+ isNextJobVirtual
299
315
  );
300
316
  } else {
301
317
  // Re get join list when first time remote trigger since external event was empty and cannot get workflow graph then
@@ -311,11 +327,12 @@ async function triggerNextJobs(config, app) {
311
327
  parentBuilds,
312
328
  groupEventBuilds,
313
329
  joinListNames,
330
+ isNextJobVirtual,
314
331
  nextJobStageName
315
332
  );
316
333
  }
317
334
 
318
- if (isVirtualJob(nextJob) && nextBuild && nextBuild.status === Status.SUCCESS) {
335
+ if (isNextJobVirtual && nextBuild && nextBuild.status === Status.SUCCESS) {
319
336
  downstreamOfNextJobsToBeProcessed.push({
320
337
  build: nextBuild,
321
338
  event: currentEvent,
@@ -128,17 +128,6 @@ function isExternalTrigger(jobName) {
128
128
  return EXTERNAL_TRIGGER_ALL.test(jobName);
129
129
  }
130
130
 
131
- /**
132
- * Checks if job is virtual
133
- * @param {Job} job Job object
134
- * @returns {Boolean}
135
- */
136
- function isVirtualJob(job) {
137
- const { annotations } = job.permutations[0];
138
-
139
- return annotations ? annotations['screwdriver.cd/virtualJob'] === true : false;
140
- }
141
-
142
131
  /**
143
132
  * Checks if job has freezeWindows
144
133
  * @param {Job} job Job object
@@ -633,18 +622,29 @@ async function getParentBuildStatus({ newBuild, joinListNames, pipelineId, build
633
622
  * @param {Job} arg.job Next job
634
623
  * @param {String|undefined} arg.pipelineId Pipeline ID
635
624
  * @param {String|undefined} arg.stageName Stage name
625
+ * @param {Boolean} arg.isVirtualJob If the job is virtual or not
636
626
  * @param {Event} arg.event Event
637
627
  * @param {Build} arg.currentBuild Current build
638
628
  * @returns {Promise<Build|null>} The newly updated/created build
639
629
  */
640
- async function handleNewBuild({ done, hasFailure, newBuild, job, pipelineId, stageName, event, currentBuild }) {
630
+ async function handleNewBuild({
631
+ done,
632
+ hasFailure,
633
+ newBuild,
634
+ job,
635
+ pipelineId,
636
+ stageName,
637
+ isVirtualJob,
638
+ event,
639
+ currentBuild
640
+ }) {
641
641
  if (!done || Status.isStarted(newBuild.status)) {
642
642
  // The virtual job does not inherit metadata because the Launcher is not executed.
643
643
  // Therefore, it is necessary to take over the metadata from the previous build.
644
644
 
645
645
  // TODO There is a bug when virtual job requires [a, b] and if "a" and "b" are completed simultaneously.
646
646
  // https://github.com/screwdriver-cd/screwdriver/issues/3287
647
- if (isVirtualJob(job) && !hasFreezeWindows(job)) {
647
+ if (isVirtualJob && !hasFreezeWindows(job)) {
648
648
  newBuild.meta = merge({}, newBuild.meta, currentBuild.meta);
649
649
 
650
650
  await newBuild.update();
@@ -669,7 +669,7 @@ async function handleNewBuild({ done, hasFailure, newBuild, job, pipelineId, sta
669
669
  }
670
670
 
671
671
  // Bypass execution of the build if the job is virtual
672
- if (isVirtualJob(job) && !hasFreezeWindows(job)) {
672
+ if (isVirtualJob && !hasFreezeWindows(job)) {
673
673
  newBuild.status = Status.SUCCESS;
674
674
  newBuild.statusMessage = BUILD_STATUS_MESSAGES.SKIP_VIRTUAL_JOB.statusMessage;
675
675
  newBuild.statusMessageType = BUILD_STATUS_MESSAGES.SKIP_VIRTUAL_JOB.statusMessageType;
@@ -934,9 +934,7 @@ async function createJoinObject(nextJobNames, current, eventFactory) {
934
934
  isExternal = true;
935
935
  }
936
936
 
937
- const node = event.workflowGraph.nodes.find(n => n.name === trimJobName(jobName));
938
- const jId = node.id;
939
- const stageName = node.stageName || null;
937
+ const jId = event.workflowGraph.nodes.find(n => n.name === trimJobName(jobName)).id;
940
938
 
941
939
  if (!joinObj[nextJobPipelineId]) joinObj[nextJobPipelineId] = {};
942
940
  const pipelineObj = joinObj[nextJobPipelineId];
@@ -956,7 +954,7 @@ async function createJoinObject(nextJobNames, current, eventFactory) {
956
954
  }
957
955
 
958
956
  if (!pipelineObj.jobs) pipelineObj.jobs = {};
959
- pipelineObj.jobs[nextJobName] = { id: jId, join: jobs, isExternal, stageName };
957
+ pipelineObj.jobs[nextJobName] = { id: jId, join: jobs, isExternal };
960
958
  }
961
959
 
962
960
  return joinObj;
@@ -1225,7 +1223,6 @@ module.exports = {
1225
1223
  buildsToRestartFilter,
1226
1224
  trimJobName,
1227
1225
  isStartFromMiddleOfCurrentStage,
1228
- isVirtualJob,
1229
1226
  hasFreezeWindows,
1230
1227
  BUILD_STATUS_MESSAGES
1231
1228
  };
@@ -43,6 +43,7 @@ class JoinBase {
43
43
  * @param {import('./helpers').ParentBuilds} parentBuilds
44
44
  * @param {String} parentBuildId
45
45
  * @param {String[]} joinListNames
46
+ * @param {Boolean} isNextJobVirtual
46
47
  * @param {String} nextJobStageName
47
48
  * @returns {Promise<Build[]|null>}
48
49
  */
@@ -54,6 +55,7 @@ class JoinBase {
54
55
  parentBuilds,
55
56
  parentBuildId,
56
57
  joinListNames,
58
+ isNextJobVirtual,
57
59
  nextJobStageName
58
60
  }) {
59
61
  let newBuild;
@@ -102,6 +104,7 @@ class JoinBase {
102
104
  newBuild,
103
105
  job: nextJob,
104
106
  pipelineId,
107
+ isVirtualJob: isNextJobVirtual,
105
108
  stageName: nextJobStageName,
106
109
  event,
107
110
  currentBuild: this.currentBuild
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const merge = require('lodash.mergewith');
4
- const { createInternalBuild, Status, BUILD_STATUS_MESSAGES, isVirtualJob, hasFreezeWindows } = require('./helpers');
4
+ const { createInternalBuild, Status, BUILD_STATUS_MESSAGES, hasFreezeWindows } = require('./helpers');
5
5
 
6
6
  /**
7
7
  * @typedef {import('screwdriver-models').BuildFactory} BuildFactory
@@ -39,15 +39,15 @@ class OrBase {
39
39
  * @param {Number} pipelineId
40
40
  * @param {Job} nextJob
41
41
  * @param {import('./helpers').ParentBuilds} parentBuilds
42
+ * @param {Boolean} isNextJobVirtual
42
43
  * @return {Promise<Build|null>}
43
44
  */
44
- async trigger(event, pipelineId, nextJob, parentBuilds) {
45
+ async trigger(event, pipelineId, nextJob, parentBuilds, isNextJobVirtual) {
45
46
  let nextBuild = await this.buildFactory.get({
46
47
  eventId: event.id,
47
48
  jobId: nextJob.id
48
49
  });
49
50
 
50
- const isNextJobVirtual = isVirtualJob(nextJob);
51
51
  const hasWindows = hasFreezeWindows(nextJob);
52
52
  const causeMessage = nextJob.name === event.startFrom ? event.causeMessage : '';
53
53
 
@@ -229,7 +229,7 @@ function hasChangesUnderRootDir(pipeline, changedFiles) {
229
229
 
230
230
  // Only check if rootDir is set
231
231
  if (rootDir) {
232
- return changes.some(file => file.startsWith(rootDir));
232
+ return changes.some(file => file.startsWith(`${rootDir}/`));
233
233
  }
234
234
 
235
235
  return true;