Skip to content

Commit a221e04

Browse files
Spencerspalger
andauthored
[pipeline/commitStatus] update commit status in baseline-capture job (#72366)
Co-authored-by: spalger <spalger@users.noreply.github.com>
1 parent c3263aa commit a221e04

File tree

3 files changed

+42
-30
lines changed

3 files changed

+42
-30
lines changed

.ci/Jenkinsfile_baseline_capture

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,25 @@ library 'kibana-pipeline-library'
44
kibanaLibrary.load()
55

66
kibanaPipeline(timeoutMinutes: 120) {
7-
ciStats.trackBuild {
8-
catchError {
9-
parallel([
10-
'oss-visualRegression': {
11-
workers.ci(name: 'oss-visualRegression', size: 's-highmem', ramDisk: true) {
12-
kibanaPipeline.functionalTestProcess('oss-visualRegression', './test/scripts/jenkins_visual_regression.sh')(1)
13-
}
14-
},
15-
'xpack-visualRegression': {
16-
workers.ci(name: 'xpack-visualRegression', size: 's-highmem', ramDisk: true) {
17-
kibanaPipeline.functionalTestProcess('xpack-visualRegression', './test/scripts/jenkins_xpack_visual_regression.sh')(1)
18-
}
19-
},
20-
])
21-
}
7+
githubCommitStatus.trackBuild(params.commit, 'kibana-ci-baseline') {
8+
ciStats.trackBuild {
9+
catchError {
10+
parallel([
11+
'oss-visualRegression': {
12+
workers.ci(name: 'oss-visualRegression', size: 's-highmem', ramDisk: true) {
13+
kibanaPipeline.functionalTestProcess('oss-visualRegression', './test/scripts/jenkins_visual_regression.sh')(1)
14+
}
15+
},
16+
'xpack-visualRegression': {
17+
workers.ci(name: 'xpack-visualRegression', size: 's-highmem', ramDisk: true) {
18+
kibanaPipeline.functionalTestProcess('xpack-visualRegression', './test/scripts/jenkins_xpack_visual_regression.sh')(1)
19+
}
20+
},
21+
])
22+
}
2223

23-
kibanaPipeline.sendMail()
24-
slackNotifications.onFailure()
24+
kibanaPipeline.sendMail()
25+
slackNotifications.onFailure()
26+
}
2527
}
2628
}

.ci/pipeline-library/src/test/githubCommitStatus.groovy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class GithubCommitStatusTest extends KibanaBasePipelineTest {
1212

1313
interface BuildState {
1414
Object get(String key)
15+
Object has(String key)
1516
}
1617

1718
interface GithubApi {
@@ -25,6 +26,7 @@ class GithubCommitStatusTest extends KibanaBasePipelineTest {
2526
buildStateMock = mock(BuildState)
2627
githubApiMock = mock(GithubApi)
2728

29+
when(buildStateMock.has('checkoutInfo')).thenReturn(true)
2830
when(buildStateMock.get('checkoutInfo')).thenReturn([ commit: 'COMMIT_HASH', ])
2931
when(githubApiMock.post(any(), any())).thenReturn(null)
3032

vars/githubCommitStatus.groovy

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,47 @@
1-
def shouldCreateStatuses() {
2-
return !githubPr.isPr() && buildState.get('checkoutInfo')
1+
def defaultCommit() {
2+
if (buildState.has('checkoutInfo')) {
3+
return buildState.get('checkoutInfo').commit
4+
}
35
}
46

5-
def onStart() {
7+
def onStart(commit = defaultCommit(), context = 'kibana-ci') {
68
catchError {
7-
if (!shouldCreateStatuses()) {
9+
if (githubPr.isPr() || !commit) {
810
return
911
}
1012

11-
def checkoutInfo = buildState.get('checkoutInfo')
12-
create(checkoutInfo.commit, 'pending', 'Build started.')
13+
create(commit, 'pending', 'Build started.', context)
1314
}
1415
}
1516

16-
def onFinish() {
17+
def onFinish(commit = defaultCommit(), context = 'kibana-ci') {
1718
catchError {
18-
if (!shouldCreateStatuses()) {
19+
if (githubPr.isPr() || !commit) {
1920
return
2021
}
2122

22-
def checkoutInfo = buildState.get('checkoutInfo')
2323
def status = buildUtils.getBuildStatus()
2424

2525
if (status == 'SUCCESS' || status == 'UNSTABLE') {
26-
create(checkoutInfo.commit, 'success', 'Build completed successfully.')
26+
create(commit, 'success', 'Build completed successfully.', context)
2727
} else if(status == 'ABORTED') {
28-
create(checkoutInfo.commit, 'error', 'Build aborted or timed out.')
28+
create(commit, 'error', 'Build aborted or timed out.', context)
2929
} else {
30-
create(checkoutInfo.commit, 'error', 'Build failed.')
30+
create(commit, 'error', 'Build failed.', context)
3131
}
3232
}
3333
}
3434

35+
def trackBuild(commit, context, Closure closure) {
36+
onStart(commit, context)
37+
catchError {
38+
closure()
39+
}
40+
onFinish(commit, context)
41+
}
42+
3543
// state: error|failure|pending|success
36-
def create(sha, state, description, context = 'kibana-ci') {
44+
def create(sha, state, description, context) {
3745
withGithubCredentials {
3846
return githubApi.post("repos/elastic/kibana/statuses/${sha}", [
3947
state: state,

0 commit comments

Comments
 (0)