2020-07-23 02:38:26 +02:00
|
|
|
def defaultCommit() {
|
|
|
|
if (buildState.has('checkoutInfo')) {
|
|
|
|
return buildState.get('checkoutInfo').commit
|
|
|
|
}
|
2020-06-23 22:16:17 +02:00
|
|
|
}
|
|
|
|
|
2020-07-23 02:38:26 +02:00
|
|
|
def onStart(commit = defaultCommit(), context = 'kibana-ci') {
|
2020-06-23 22:16:17 +02:00
|
|
|
catchError {
|
2020-07-23 02:38:26 +02:00
|
|
|
if (githubPr.isPr() || !commit) {
|
2020-06-23 22:16:17 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-07-23 02:38:26 +02:00
|
|
|
create(commit, 'pending', 'Build started.', context)
|
2020-06-23 22:16:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-23 02:38:26 +02:00
|
|
|
def onFinish(commit = defaultCommit(), context = 'kibana-ci') {
|
2020-06-23 22:16:17 +02:00
|
|
|
catchError {
|
2020-07-23 02:38:26 +02:00
|
|
|
if (githubPr.isPr() || !commit) {
|
2020-06-23 22:16:17 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
def status = buildUtils.getBuildStatus()
|
|
|
|
|
|
|
|
if (status == 'SUCCESS' || status == 'UNSTABLE') {
|
2020-07-23 02:38:26 +02:00
|
|
|
create(commit, 'success', 'Build completed successfully.', context)
|
2020-06-23 22:16:17 +02:00
|
|
|
} else if(status == 'ABORTED') {
|
2020-07-23 02:38:26 +02:00
|
|
|
create(commit, 'error', 'Build aborted or timed out.', context)
|
2020-06-23 22:16:17 +02:00
|
|
|
} else {
|
2020-07-23 02:38:26 +02:00
|
|
|
create(commit, 'error', 'Build failed.', context)
|
2020-06-23 22:16:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-23 02:38:26 +02:00
|
|
|
def trackBuild(commit, context, Closure closure) {
|
|
|
|
onStart(commit, context)
|
|
|
|
catchError {
|
|
|
|
closure()
|
|
|
|
}
|
|
|
|
onFinish(commit, context)
|
|
|
|
}
|
|
|
|
|
2020-06-23 22:16:17 +02:00
|
|
|
// state: error|failure|pending|success
|
2020-07-23 02:38:26 +02:00
|
|
|
def create(sha, state, description, context) {
|
2020-06-23 22:16:17 +02:00
|
|
|
withGithubCredentials {
|
2020-07-15 00:32:20 +02:00
|
|
|
return githubApi.post("repos/elastic/kibana/statuses/${sha}", [
|
|
|
|
state: state,
|
|
|
|
description: description,
|
|
|
|
context: context,
|
|
|
|
target_url: env.BUILD_URL
|
|
|
|
])
|
2020-06-23 22:16:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this
|