screwdriver-api 7.0.171 → 7.0.173

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": "7.0.171",
3
+ "version": "7.0.173",
4
4
  "description": "API server for the Screwdriver.cd service",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -36,6 +36,7 @@ const {
36
36
  buildsToRestartFilter,
37
37
  trimJobName,
38
38
  getParallelBuilds,
39
+ isStartFromMiddleOfStage,
39
40
  Status
40
41
  } = require('./triggers/helpers');
41
42
 
@@ -77,7 +78,8 @@ async function triggerNextJobs(config, app) {
77
78
  /** @type Array<string> */
78
79
  const nextJobsTrigger = workflowParser.getNextJobs(currentEvent.workflowGraph, {
79
80
  trigger: currentJob.name,
80
- chainPR: currentPipeline.chainPR
81
+ chainPR: currentPipeline.chainPR,
82
+ startFrom: currentEvent.startFrom
81
83
  });
82
84
  const pipelineJoinData = await createJoinObject(nextJobsTrigger, current, eventFactory);
83
85
  const originalCurrentJobName = trimJobName(currentJob.name);
@@ -114,7 +116,10 @@ async function triggerNextJobs(config, app) {
114
116
  * 2. ([~D,B,C]->A) currentJob=D, nextJob=A, joinList(A)=[B,C]
115
117
  * joinList doesn't include D, so start A
116
118
  */
117
- if (isOrTrigger(currentEvent.workflowGraph, originalCurrentJobName, trimJobName(nextJobName))) {
119
+ if (
120
+ isOrTrigger(currentEvent.workflowGraph, originalCurrentJobName, trimJobName(nextJobName)) ||
121
+ isStartFromMiddleOfStage(currentJob.name, currentEvent.startFrom, currentEvent.workflowGraph)
122
+ ) {
118
123
  nextBuild = await orTrigger.execute(
119
124
  currentEvent,
120
125
  currentPipeline.id,
@@ -6,6 +6,7 @@ const merge = require('lodash.mergewith');
6
6
  const schema = require('screwdriver-data-schema');
7
7
  const { EXTERNAL_TRIGGER_ALL } = schema.config.regex;
8
8
  const { getFullStageJobName } = require('../../helper');
9
+ const STAGE_SETUP_PATTERN = /^stage@([\w-]+)(?::setup)$/;
9
10
 
10
11
  /**
11
12
  * @typedef {import('screwdriver-models').JobFactory} JobFactory
@@ -1063,6 +1064,38 @@ function buildsToRestartFilter(joinPipeline, groupEventBuilds, currentEvent, cur
1063
1064
  .filter(build => build !== null);
1064
1065
  }
1065
1066
 
1067
+ /**
1068
+ * Check if the job is setup job with setup suffix
1069
+ * @param {String} jobName Job name
1070
+ * @return {Boolean}
1071
+ */
1072
+ function isStageSetup(jobName) {
1073
+ return STAGE_SETUP_PATTERN.test(jobName);
1074
+ }
1075
+
1076
+ /**
1077
+ * Check if the job is a stage job
1078
+ * @param {String} jobName Job name
1079
+ * @param {Object} workflowGraph Workflow Graph
1080
+ * @return {Boolean}
1081
+ */
1082
+ function isStageJob(workflowGraph, jobName) {
1083
+ const jobNode = workflowGraph.nodes.find(n => n.name === jobName);
1084
+
1085
+ return jobNode.stageName !== undefined;
1086
+ }
1087
+
1088
+ /**
1089
+ * Check if the current job is a stage setup and the next job is a non-setup stage job
1090
+ * @param {String} triggerJob Current job
1091
+ * @param {String} startFrom Next job
1092
+ * @param {Object} workflowGraph Workflow Graph
1093
+ * @return {Boolean}
1094
+ */
1095
+ function isStartFromMiddleOfStage(triggerJob, startFrom, workflowGraph) {
1096
+ return isStageSetup(triggerJob) && !isStageSetup(startFrom) && isStageJob(workflowGraph, startFrom);
1097
+ }
1098
+
1066
1099
  module.exports = {
1067
1100
  Status,
1068
1101
  parseJobInfo,
@@ -1085,5 +1118,6 @@ module.exports = {
1085
1118
  extractCurrentPipelineJoinData,
1086
1119
  extractExternalJoinData,
1087
1120
  buildsToRestartFilter,
1088
- trimJobName
1121
+ trimJobName,
1122
+ isStartFromMiddleOfStage
1089
1123
  };