Skip to content

Commit

Permalink
[pipeline/commitStatus] update commit status in baseline-capture job (#…
Browse files Browse the repository at this point in the history
…72366)

Co-authored-by: spalger <[email protected]>
  • Loading branch information
Spencer and spalger authored Jul 20, 2020
1 parent c3263aa commit a221e04
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 30 deletions.
36 changes: 19 additions & 17 deletions .ci/Jenkinsfile_baseline_capture
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,25 @@ library 'kibana-pipeline-library'
kibanaLibrary.load()

kibanaPipeline(timeoutMinutes: 120) {
ciStats.trackBuild {
catchError {
parallel([
'oss-visualRegression': {
workers.ci(name: 'oss-visualRegression', size: 's-highmem', ramDisk: true) {
kibanaPipeline.functionalTestProcess('oss-visualRegression', './test/scripts/jenkins_visual_regression.sh')(1)
}
},
'xpack-visualRegression': {
workers.ci(name: 'xpack-visualRegression', size: 's-highmem', ramDisk: true) {
kibanaPipeline.functionalTestProcess('xpack-visualRegression', './test/scripts/jenkins_xpack_visual_regression.sh')(1)
}
},
])
}
githubCommitStatus.trackBuild(params.commit, 'kibana-ci-baseline') {
ciStats.trackBuild {
catchError {
parallel([
'oss-visualRegression': {
workers.ci(name: 'oss-visualRegression', size: 's-highmem', ramDisk: true) {
kibanaPipeline.functionalTestProcess('oss-visualRegression', './test/scripts/jenkins_visual_regression.sh')(1)
}
},
'xpack-visualRegression': {
workers.ci(name: 'xpack-visualRegression', size: 's-highmem', ramDisk: true) {
kibanaPipeline.functionalTestProcess('xpack-visualRegression', './test/scripts/jenkins_xpack_visual_regression.sh')(1)
}
},
])
}

kibanaPipeline.sendMail()
slackNotifications.onFailure()
kibanaPipeline.sendMail()
slackNotifications.onFailure()
}
}
}
2 changes: 2 additions & 0 deletions .ci/pipeline-library/src/test/githubCommitStatus.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class GithubCommitStatusTest extends KibanaBasePipelineTest {

interface BuildState {
Object get(String key)
Object has(String key)
}

interface GithubApi {
Expand All @@ -25,6 +26,7 @@ class GithubCommitStatusTest extends KibanaBasePipelineTest {
buildStateMock = mock(BuildState)
githubApiMock = mock(GithubApi)

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

Expand Down
34 changes: 21 additions & 13 deletions vars/githubCommitStatus.groovy
Original file line number Diff line number Diff line change
@@ -1,39 +1,47 @@
def shouldCreateStatuses() {
return !githubPr.isPr() && buildState.get('checkoutInfo')
def defaultCommit() {
if (buildState.has('checkoutInfo')) {
return buildState.get('checkoutInfo').commit
}
}

def onStart() {
def onStart(commit = defaultCommit(), context = 'kibana-ci') {
catchError {
if (!shouldCreateStatuses()) {
if (githubPr.isPr() || !commit) {
return
}

def checkoutInfo = buildState.get('checkoutInfo')
create(checkoutInfo.commit, 'pending', 'Build started.')
create(commit, 'pending', 'Build started.', context)
}
}

def onFinish() {
def onFinish(commit = defaultCommit(), context = 'kibana-ci') {
catchError {
if (!shouldCreateStatuses()) {
if (githubPr.isPr() || !commit) {
return
}

def checkoutInfo = buildState.get('checkoutInfo')
def status = buildUtils.getBuildStatus()

if (status == 'SUCCESS' || status == 'UNSTABLE') {
create(checkoutInfo.commit, 'success', 'Build completed successfully.')
create(commit, 'success', 'Build completed successfully.', context)
} else if(status == 'ABORTED') {
create(checkoutInfo.commit, 'error', 'Build aborted or timed out.')
create(commit, 'error', 'Build aborted or timed out.', context)
} 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
def create(sha, state, description, context = 'kibana-ci') {
def create(sha, state, description, context) {
withGithubCredentials {
return githubApi.post("repos/elastic/kibana/statuses/${sha}", [
state: state,
Expand Down

0 comments on commit a221e04

Please sign in to comment.