Co-authored-by: spalger <spalger@users.noreply.github.com> Co-authored-by: spalger <spalger@users.noreply.github.com>
This commit is contained in:
parent
f155e0ad3b
commit
3b4d052871
|
@ -4,6 +4,7 @@ library 'kibana-pipeline-library'
|
||||||
kibanaLibrary.load()
|
kibanaLibrary.load()
|
||||||
|
|
||||||
kibanaPipeline(timeoutMinutes: 120) {
|
kibanaPipeline(timeoutMinutes: 120) {
|
||||||
|
githubCommitStatus.trackBuild(params.commit, 'kibana-ci-baseline') {
|
||||||
ciStats.trackBuild {
|
ciStats.trackBuild {
|
||||||
catchError {
|
catchError {
|
||||||
parallel([
|
parallel([
|
||||||
|
@ -23,4 +24,5 @@ kibanaPipeline(timeoutMinutes: 120) {
|
||||||
kibanaPipeline.sendMail()
|
kibanaPipeline.sendMail()
|
||||||
slackNotifications.onFailure()
|
slackNotifications.onFailure()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ class GithubCommitStatusTest extends KibanaBasePipelineTest {
|
||||||
|
|
||||||
interface BuildState {
|
interface BuildState {
|
||||||
Object get(String key)
|
Object get(String key)
|
||||||
|
Object has(String key)
|
||||||
}
|
}
|
||||||
|
|
||||||
interface GithubApi {
|
interface GithubApi {
|
||||||
|
@ -25,6 +26,7 @@ class GithubCommitStatusTest extends KibanaBasePipelineTest {
|
||||||
buildStateMock = mock(BuildState)
|
buildStateMock = mock(BuildState)
|
||||||
githubApiMock = mock(GithubApi)
|
githubApiMock = mock(GithubApi)
|
||||||
|
|
||||||
|
when(buildStateMock.has('checkoutInfo')).thenReturn(true)
|
||||||
when(buildStateMock.get('checkoutInfo')).thenReturn([ commit: 'COMMIT_HASH', ])
|
when(buildStateMock.get('checkoutInfo')).thenReturn([ commit: 'COMMIT_HASH', ])
|
||||||
when(githubApiMock.post(any(), any())).thenReturn(null)
|
when(githubApiMock.post(any(), any())).thenReturn(null)
|
||||||
|
|
||||||
|
|
|
@ -1,39 +1,47 @@
|
||||||
def shouldCreateStatuses() {
|
def defaultCommit() {
|
||||||
return !githubPr.isPr() && buildState.get('checkoutInfo')
|
if (buildState.has('checkoutInfo')) {
|
||||||
}
|
return buildState.get('checkoutInfo').commit
|
||||||
|
|
||||||
def onStart() {
|
|
||||||
catchError {
|
|
||||||
if (!shouldCreateStatuses()) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
def checkoutInfo = buildState.get('checkoutInfo')
|
|
||||||
create(checkoutInfo.commit, 'pending', 'Build started.')
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def onFinish() {
|
def onStart(commit = defaultCommit(), context = 'kibana-ci') {
|
||||||
catchError {
|
catchError {
|
||||||
if (!shouldCreateStatuses()) {
|
if (githubPr.isPr() || !commit) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
create(commit, 'pending', 'Build started.', context)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def onFinish(commit = defaultCommit(), context = 'kibana-ci') {
|
||||||
|
catchError {
|
||||||
|
if (githubPr.isPr() || !commit) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
def checkoutInfo = buildState.get('checkoutInfo')
|
|
||||||
def status = buildUtils.getBuildStatus()
|
def status = buildUtils.getBuildStatus()
|
||||||
|
|
||||||
if (status == 'SUCCESS' || status == 'UNSTABLE') {
|
if (status == 'SUCCESS' || status == 'UNSTABLE') {
|
||||||
create(checkoutInfo.commit, 'success', 'Build completed successfully.')
|
create(commit, 'success', 'Build completed successfully.', context)
|
||||||
} else if(status == 'ABORTED') {
|
} else if(status == 'ABORTED') {
|
||||||
create(checkoutInfo.commit, 'error', 'Build aborted or timed out.')
|
create(commit, 'error', 'Build aborted or timed out.', context)
|
||||||
} else {
|
} else {
|
||||||
create(checkoutInfo.commit, 'error', 'Build failed.')
|
create(commit, 'error', 'Build failed.', context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def trackBuild(commit, context, Closure closure) {
|
||||||
|
onStart(commit, context)
|
||||||
|
catchError {
|
||||||
|
closure()
|
||||||
|
}
|
||||||
|
onFinish(commit, context)
|
||||||
|
}
|
||||||
|
|
||||||
// state: error|failure|pending|success
|
// state: error|failure|pending|success
|
||||||
def create(sha, state, description, context = 'kibana-ci') {
|
def create(sha, state, description, context) {
|
||||||
withGithubCredentials {
|
withGithubCredentials {
|
||||||
return githubApi.post("repos/elastic/kibana/statuses/${sha}", [
|
return githubApi.post("repos/elastic/kibana/statuses/${sha}", [
|
||||||
state: state,
|
state: state,
|
||||||
|
|
Loading…
Reference in a new issue