screwdriver-api 7.0.145 → 7.0.147

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.145",
3
+ "version": "7.0.147",
4
4
  "description": "API server for the Screwdriver.cd service",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -93,7 +93,7 @@ async function triggerNextJobs(config, app) {
93
93
  for (const [nextJobName, nextJob] of Object.entries(currentPipelineNextJobs)) {
94
94
  const nextJobId = nextJob.id || (await getJobId(nextJobName, currentPipeline.id, jobFactory));
95
95
  const { isVirtual: isNextJobVirtual, stageName: nextJobStageName } = nextJob;
96
- const resource = `pipeline:${currentPipeline.id}:event:${currentEvent.id}`;
96
+ const resource = `pipeline:${currentPipeline.id}:groupEvent:${currentEvent.groupEventId}`;
97
97
  let lock;
98
98
  let nextBuild;
99
99
 
@@ -224,76 +224,87 @@ async function triggerNextJobs(config, app) {
224
224
  externalEventConfig.parentBuilds = buildsToRestart[0].parentBuilds;
225
225
  }
226
226
 
227
- externalEvent = await createExternalEvent(externalEventConfig);
227
+ try {
228
+ externalEvent = await createExternalEvent(externalEventConfig);
229
+ } catch (err) {
230
+ // The case of triggered external pipeline which is already deleted from DB, etc
231
+ logger.error(
232
+ `Error in createExternalEvent:${joinedPipelineId} from pipeline:${currentPipeline.id}-${currentJob.name}-event:${currentEvent.id}`,
233
+ err
234
+ );
235
+ }
228
236
  }
229
237
 
230
- for (const [nextJobName, nextJob] of Object.entries(joinedPipeline.jobs)) {
231
- const nextJobId = nextJob.id || (await getJobId(nextJobName, currentPipeline.id, jobFactory));
232
- const { isVirtual: isNextJobVirtual, stageName: nextJobStageName } = nextJob;
238
+ // Skip trigger process if createExternalEvent fails
239
+ if (externalEvent) {
240
+ for (const [nextJobName, nextJob] of Object.entries(joinedPipeline.jobs)) {
241
+ const nextJobId = nextJob.id || (await getJobId(nextJobName, currentPipeline.id, jobFactory));
242
+ const { isVirtual: isNextJobVirtual, stageName: nextJobStageName } = nextJob;
243
+
244
+ const { parentBuilds } = parseJobInfo({
245
+ joinObj: joinedPipeline.jobs,
246
+ currentBuild,
247
+ currentPipeline,
248
+ currentJob,
249
+ nextJobName,
250
+ nextPipelineId: joinedPipelineId
251
+ });
233
252
 
234
- const { parentBuilds } = parseJobInfo({
235
- joinObj: joinedPipeline.jobs,
236
- currentBuild,
237
- currentPipeline,
238
- currentJob,
239
- nextJobName,
240
- nextPipelineId: joinedPipelineId
241
- });
253
+ let nextBuild;
242
254
 
243
- let nextBuild;
255
+ try {
256
+ if (resource) lock = await locker.lock(resource);
244
257
 
245
- try {
246
- if (resource) lock = await locker.lock(resource);
247
-
248
- if (isOrTrigger(externalEvent.workflowGraph, remoteTriggerName, nextJobName)) {
249
- nextBuild = await remoteTrigger.execute(
250
- externalEvent,
251
- externalEvent.pipelineId,
252
- nextJobName,
253
- nextJobId,
254
- parentBuilds,
255
- isNextJobVirtual
256
- );
257
- } else {
258
- // Re get join list when first time remote trigger since external event was empty and cannot get workflow graph then
259
- const joinList =
260
- nextJob.join.length > 0
261
- ? nextJob.join
262
- : workflowParser.getSrcForJoin(externalEvent.workflowGraph, { jobName: nextJobName });
263
- const joinListNames = joinList.map(j => j.name);
264
-
265
- nextBuild = await remoteJoin.execute(
266
- externalEvent,
267
- nextJobName,
268
- nextJobId,
269
- parentBuilds,
270
- groupEventBuilds,
271
- joinListNames,
272
- isNextJobVirtual,
273
- nextJobStageName
258
+ if (isOrTrigger(externalEvent.workflowGraph, remoteTriggerName, nextJobName)) {
259
+ nextBuild = await remoteTrigger.execute(
260
+ externalEvent,
261
+ externalEvent.pipelineId,
262
+ nextJobName,
263
+ nextJobId,
264
+ parentBuilds,
265
+ isNextJobVirtual
266
+ );
267
+ } else {
268
+ // Re get join list when first time remote trigger since external event was empty and cannot get workflow graph then
269
+ const joinList =
270
+ nextJob.join.length > 0
271
+ ? nextJob.join
272
+ : workflowParser.getSrcForJoin(externalEvent.workflowGraph, { jobName: nextJobName });
273
+ const joinListNames = joinList.map(j => j.name);
274
+
275
+ nextBuild = await remoteJoin.execute(
276
+ externalEvent,
277
+ nextJobName,
278
+ nextJobId,
279
+ parentBuilds,
280
+ groupEventBuilds,
281
+ joinListNames,
282
+ isNextJobVirtual,
283
+ nextJobStageName
284
+ );
285
+ }
286
+
287
+ if (isNextJobVirtual && nextBuild.status === Status.SUCCESS) {
288
+ const nextJobModel = await nextBuild.job;
289
+
290
+ downstreamOfNextJobsToBeProcessed.push({
291
+ build: nextBuild,
292
+ event: currentEvent,
293
+ job: nextJobModel,
294
+ pipeline: await nextJobModel.pipeline,
295
+ scmContext: config.scmContext,
296
+ username: config.username
297
+ });
298
+ }
299
+ } catch (err) {
300
+ logger.error(
301
+ `Error in triggerJobsInExternalPipeline:${joinedPipelineId} from pipeline:${currentPipeline.id}-${currentJob.name}-event:${currentEvent.id} `,
302
+ err
274
303
  );
275
304
  }
276
305
 
277
- if (isNextJobVirtual && nextBuild.status === Status.SUCCESS) {
278
- const nextJobModel = await nextBuild.job;
279
-
280
- downstreamOfNextJobsToBeProcessed.push({
281
- build: nextBuild,
282
- event: currentEvent,
283
- job: nextJobModel,
284
- pipeline: await nextJobModel.pipeline,
285
- scmContext: config.scmContext,
286
- username: config.username
287
- });
288
- }
289
- } catch (err) {
290
- logger.error(
291
- `Error in triggerJobsInExternalPipeline:${joinedPipelineId} from pipeline:${currentPipeline.id}-${currentJob.name}-event:${currentEvent.id} `,
292
- err
293
- );
306
+ await locker.unlock(lock, resource);
294
307
  }
295
-
296
- await locker.unlock(lock, resource);
297
308
  }
298
309
  }
299
310
 
@@ -82,11 +82,21 @@ class AndTrigger extends JoinBase {
82
82
  }
83
83
  }
84
84
 
85
+ if (!nextBuild) {
86
+ // If the build to join is in the child event, its event id is greater than current event.
87
+ nextBuild = relatedBuilds.find(b => b.jobId === nextJobId && b.eventId > this.currentEvent.id);
88
+ }
89
+
85
90
  const newParentBuilds = mergeParentBuilds(parentBuilds, relatedBuilds, this.currentEvent);
91
+ let nextEvent = this.currentEvent;
92
+
93
+ if (nextBuild) {
94
+ nextEvent = await this.eventFactory.get({ id: nextBuild.eventId });
95
+ }
86
96
 
87
97
  return this.processNextBuild({
88
98
  pipelineId: this.pipelineId,
89
- event: this.currentEvent,
99
+ event: nextEvent,
90
100
  nextBuild,
91
101
  nextJobName,
92
102
  nextJobId,