screwdriver-api 7.0.129 → 7.0.131
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/index.js +174 -1137
- package/plugins/builds/triggers/and.js +100 -0
- package/plugins/builds/triggers/helpers.js +1069 -0
- package/plugins/builds/triggers/joinBase.js +115 -0
- package/plugins/builds/triggers/or.js +27 -0
- package/plugins/builds/triggers/orBase.js +80 -0
- package/plugins/builds/triggers/remoteJoin.js +70 -0
- package/plugins/builds/triggers/remoteTrigger.js +27 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const logger = require('screwdriver-logger');
|
|
4
|
+
const { JoinBase } = require('./joinBase');
|
|
5
|
+
const { getParallelBuilds, getBuildsForGroupEvent, mergeParentBuilds } = require('./helpers');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @typedef {import('screwdriver-models').EventFactory} EventFactory
|
|
9
|
+
* @typedef {import('screwdriver-models').BuildFactory} BuildFactory
|
|
10
|
+
* @typedef {import('screwdriver-models').JobFactory} JobFactory
|
|
11
|
+
* @typedef {import('screwdriver-models/lib/event')} Event
|
|
12
|
+
* @typedef {import('screwdriver-models/lib/build')} Build
|
|
13
|
+
* @typedef {import('screwdriver-models/lib/stage')} Stage
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
class AndTrigger extends JoinBase {
|
|
17
|
+
/**
|
|
18
|
+
* @param {Object} app
|
|
19
|
+
* @param {Object} config
|
|
20
|
+
* @param {Stage} config.stage
|
|
21
|
+
* @param {Event} currentEvent
|
|
22
|
+
*/
|
|
23
|
+
constructor(app, config, currentEvent) {
|
|
24
|
+
super(app, config);
|
|
25
|
+
|
|
26
|
+
this.pipelineId = config.pipeline.id;
|
|
27
|
+
this.stage = config.stage;
|
|
28
|
+
this.currentEvent = currentEvent;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Get finished builds related to current event group
|
|
33
|
+
* @return {Promise<Build[]|null>}
|
|
34
|
+
*/
|
|
35
|
+
async fetchRelatedBuilds() {
|
|
36
|
+
const relatedBuilds = await getBuildsForGroupEvent(this.currentEvent.groupEventId, this.buildFactory);
|
|
37
|
+
|
|
38
|
+
if (this.currentEvent.parentEventId) {
|
|
39
|
+
// FIXME: On restart cases parentEventId should be fetched
|
|
40
|
+
// from first event in the group
|
|
41
|
+
const parallelBuilds = await getParallelBuilds({
|
|
42
|
+
eventFactory: this.eventFactory,
|
|
43
|
+
parentEventId: this.currentEvent.parentEventId,
|
|
44
|
+
pipelineId: this.pipelineId
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
relatedBuilds.push(...parallelBuilds);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return relatedBuilds;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Trigger the next jobs of the current job
|
|
55
|
+
* @param {String} nextJobName
|
|
56
|
+
* @param {String} nextJobId
|
|
57
|
+
* @param {Record<String, Object>} parentBuilds
|
|
58
|
+
* @param {String[]} joinListNames
|
|
59
|
+
* @returns {Promise<Build>}
|
|
60
|
+
*/
|
|
61
|
+
async execute(nextJobName, nextJobId, parentBuilds, joinListNames) {
|
|
62
|
+
logger.info(`Fetching finished builds for event ${this.currentEvent.id}`);
|
|
63
|
+
|
|
64
|
+
const relatedBuilds = await this.fetchRelatedBuilds();
|
|
65
|
+
|
|
66
|
+
// Find the next build from the related builds for this event
|
|
67
|
+
let nextBuild = relatedBuilds.find(b => b.jobId === nextJobId && b.eventId === this.currentEvent.id);
|
|
68
|
+
|
|
69
|
+
if (!nextBuild) {
|
|
70
|
+
// 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.
|
|
71
|
+
// In that case, `nextBuild` will be null and will not be triggered even though there is a build that should be triggered.
|
|
72
|
+
// Now we need to check for the existence of a build that should be triggered in its own event.
|
|
73
|
+
nextBuild = await this.buildFactory.get({
|
|
74
|
+
eventId: this.currentEvent.id,
|
|
75
|
+
jobId: nextJobId
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
if (nextBuild) {
|
|
79
|
+
relatedBuilds.push(nextBuild);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const newParentBuilds = mergeParentBuilds(parentBuilds, relatedBuilds, this.currentEvent);
|
|
84
|
+
|
|
85
|
+
return this.processNextBuild({
|
|
86
|
+
pipelineId: this.pipelineId,
|
|
87
|
+
event: this.currentEvent,
|
|
88
|
+
nextBuild,
|
|
89
|
+
nextJobName,
|
|
90
|
+
nextJobId,
|
|
91
|
+
parentBuilds: newParentBuilds,
|
|
92
|
+
parentBuildId: this.currentBuild.id,
|
|
93
|
+
joinListNames
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
module.exports = {
|
|
99
|
+
AndTrigger
|
|
100
|
+
};
|