kibana/vars/githubCommitStatus.groovy
spalger b1433e6317 remove unnecessary context reference from trigger job
(cherry picked from commit 817fdf9b439e85c3ddfda126b3efb4e45c36006b)
2020-07-14 15:08:29 -07:00

48 lines
1.1 KiB
Groovy

def shouldCreateStatuses() {
return !githubPr.isPr() && buildState.get('checkoutInfo')
}
def onStart() {
catchError {
if (!shouldCreateStatuses()) {
return
}
def checkoutInfo = buildState.get('checkoutInfo')
create(checkoutInfo.commit, 'pending', 'Build started.')
}
}
def onFinish() {
catchError {
if (!shouldCreateStatuses()) {
return
}
def checkoutInfo = buildState.get('checkoutInfo')
def status = buildUtils.getBuildStatus()
if (status == 'SUCCESS' || status == 'UNSTABLE') {
create(checkoutInfo.commit, 'success', 'Build completed successfully.')
} else if(status == 'ABORTED') {
create(checkoutInfo.commit, 'error', 'Build aborted or timed out.')
} else {
create(checkoutInfo.commit, 'error', 'Build failed.')
}
}
}
// state: error|failure|pending|success
def create(sha, state, description, context = 'kibana-ci') {
withGithubCredentials {
return githubApi.post("repos/elastic/kibana/statuses/${sha}", [
state: state,
description: description,
context: context,
target_url: env.BUILD_URL
])
}
}
return this