screwdriver-api 8.0.13 → 8.0.14
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 +1 -1
- package/plugins/builds/triggers/and.js +51 -12
package/package.json
CHANGED
|
@@ -50,6 +50,42 @@ class AndTrigger extends JoinBase {
|
|
|
50
50
|
return relatedBuilds;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
/**
|
|
54
|
+
* Get next build in the latest child evnet
|
|
55
|
+
* @param {Job} nextJob next job
|
|
56
|
+
* @returns {Promise<Build|null>}
|
|
57
|
+
*/
|
|
58
|
+
async fetchNextBuildInChildEvents(nextJob) {
|
|
59
|
+
const childEvents = await this.eventFactory.list({
|
|
60
|
+
params: {
|
|
61
|
+
parentEventId: this.currentEvent.id,
|
|
62
|
+
pipelineId: this.pipelineId
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
if (childEvents.length === 0) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const childEventBuilds = await this.buildFactory.list({
|
|
71
|
+
params: {
|
|
72
|
+
eventId: childEvents.map(e => e.id),
|
|
73
|
+
jobId: nextJob.id
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
if (childEventBuilds.length === 0) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Get the build of the latest evnet
|
|
82
|
+
const childEventNextBuild = childEventBuilds.reduce((l, r) => {
|
|
83
|
+
return l.eventId > r.eventId ? l : r;
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
return childEventNextBuild;
|
|
87
|
+
}
|
|
88
|
+
|
|
53
89
|
/**
|
|
54
90
|
* Trigger the next jobs of the current job
|
|
55
91
|
* @param {Job} nextJob
|
|
@@ -63,28 +99,31 @@ class AndTrigger extends JoinBase {
|
|
|
63
99
|
logger.info(`Fetching finished builds for event ${this.currentEvent.id}`);
|
|
64
100
|
|
|
65
101
|
const relatedBuilds = await this.fetchRelatedBuilds();
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
102
|
+
const childEventBuild = await this.fetchNextBuildInChildEvents(nextJob);
|
|
103
|
+
const groupEventsNextBuild = relatedBuilds.find(
|
|
104
|
+
b => b.jobId === nextJob.id && b.eventId > this.currentEvent.id
|
|
105
|
+
);
|
|
106
|
+
let currentEventNextBuild = relatedBuilds.find(
|
|
107
|
+
b => b.jobId === nextJob.id && b.eventId === this.currentEvent.id
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
// Find the next build of this event
|
|
111
|
+
if (!currentEventNextBuild) {
|
|
71
112
|
// If the build to join fails and it succeeds on restart, depending on the timing, the latest build will be that of a child event.
|
|
72
113
|
// In that case, `nextBuild` will be null and will not be triggered even though there is a build that should be triggered.
|
|
73
114
|
// Now we need to check for the existence of a build that should be triggered in its own event.
|
|
74
|
-
|
|
115
|
+
currentEventNextBuild = await this.buildFactory.get({
|
|
75
116
|
eventId: this.currentEvent.id,
|
|
76
117
|
jobId: nextJob.id
|
|
77
118
|
});
|
|
78
119
|
|
|
79
|
-
if (
|
|
80
|
-
relatedBuilds.push(
|
|
120
|
+
if (currentEventNextBuild) {
|
|
121
|
+
relatedBuilds.push(currentEventNextBuild);
|
|
81
122
|
}
|
|
82
123
|
}
|
|
83
124
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
nextBuild = relatedBuilds.find(b => b.jobId === nextJob.id && b.eventId > this.currentEvent.id);
|
|
87
|
-
}
|
|
125
|
+
const nextBuild = childEventBuild || currentEventNextBuild || groupEventsNextBuild;
|
|
126
|
+
|
|
88
127
|
const newParentBuilds = mergeParentBuilds(parentBuilds, relatedBuilds, this.currentEvent, undefined);
|
|
89
128
|
let nextEvent = this.currentEvent;
|
|
90
129
|
|