Skip to content

Commit 56c3b91

Browse files
committed
[CI] Add baseline trigger job
1 parent bb03b75 commit 56c3b91

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

.ci/Jenkinsfile_baseline_trigger

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/groovy
2+
3+
def MAXIMUM_COMMITS_TO_CHECK = 10
4+
def MAXIMUM_COMMITS_TO_BUILD = 5
5+
6+
if (!params.branches_yaml) {
7+
error "'branches_yaml' parameter must be specified"
8+
}
9+
10+
def additionalBranches = []
11+
12+
def branches = readYaml(text: params.branches_yaml) + additionalBranches
13+
14+
library 'kibana-pipeline-library'
15+
kibanaLibrary.load()
16+
17+
withGithubCredentials {
18+
branches.each { branch ->
19+
stage(branch) {
20+
def commits = getCommits(branch, MAXIMUM_COMMITS_TO_CHECK, MAXIMUM_COMMITS_TO_BUILD)
21+
22+
commits.take(MAXIMUM_COMMITS_TO_BUILD).each { commit ->
23+
catchErrors {
24+
githubCommitStatus.create(commit, 'pending', 'Baseline started.', context = 'kibana-ci-baseline')
25+
26+
build(
27+
propagate: false,
28+
wait: false,
29+
job: 'elastic+kibana+baseline',
30+
parameters: [
31+
string(name: 'branch_specifier', value: branch),
32+
string(name: 'commit', value: commit),
33+
]
34+
)
35+
}
36+
}
37+
}
38+
}
39+
}
40+
41+
def getCommits(String branch, maximumCommitsToCheck, maximumCommitsToBuild) {
42+
print "Getting latest commits for ${branch}..."
43+
def commits = githubApi.get("repos/elastic/kibana/commits?sha=${branch}").take(maximumCommitsToCheck).collect { it.sha }
44+
def commitsToBuild = []
45+
46+
for (commit in commits) {
47+
print "Getting statuses for ${commit}"
48+
def status = githubApi.get("repos/elastic/kibana/statuses/${commit}").find { it.context == 'kibana-ci-baseline' }
49+
print "Commit '${commit}' already built? ${status ? 'Yes' : 'No'}"
50+
51+
if (!status) {
52+
commitsToBuild << commit
53+
}
54+
55+
if (commitsToBuild.size() >= maximumCommitsToBuild) {
56+
break;
57+
}
58+
}
59+
60+
return commitsToBuild.reverse()
61+
}

0 commit comments

Comments
 (0)