From a221e04b3caa161cccef45985032c403f74fb974 Mon Sep 17 00:00:00 2001 From: Spencer Date: Mon, 20 Jul 2020 15:06:02 -0700 Subject: [PATCH] [pipeline/commitStatus] update commit status in baseline-capture job (#72366) Co-authored-by: spalger --- .ci/Jenkinsfile_baseline_capture | 36 ++++++++++--------- .../src/test/githubCommitStatus.groovy | 2 ++ vars/githubCommitStatus.groovy | 34 +++++++++++------- 3 files changed, 42 insertions(+), 30 deletions(-) diff --git a/.ci/Jenkinsfile_baseline_capture b/.ci/Jenkinsfile_baseline_capture index 3f90a6bc05af0..b0d3591821642 100644 --- a/.ci/Jenkinsfile_baseline_capture +++ b/.ci/Jenkinsfile_baseline_capture @@ -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() + } } } diff --git a/.ci/pipeline-library/src/test/githubCommitStatus.groovy b/.ci/pipeline-library/src/test/githubCommitStatus.groovy index 17878624b73cf..c770d5596f9cb 100644 --- a/.ci/pipeline-library/src/test/githubCommitStatus.groovy +++ b/.ci/pipeline-library/src/test/githubCommitStatus.groovy @@ -12,6 +12,7 @@ class GithubCommitStatusTest extends KibanaBasePipelineTest { interface BuildState { Object get(String key) + Object has(String key) } interface GithubApi { @@ -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) diff --git a/vars/githubCommitStatus.groovy b/vars/githubCommitStatus.groovy index 17d3c234f6928..248d226169a61 100644 --- a/vars/githubCommitStatus.groovy +++ b/vars/githubCommitStatus.groovy @@ -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,