Skip to content

Commit

Permalink
CI: customise GitHub PR comment
Browse files Browse the repository at this point in the history
  • Loading branch information
v1v committed Apr 19, 2021
1 parent 8f09d7f commit 6bcaf13
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
60 changes: 60 additions & 0 deletions .ci/github-comment.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!-- See for further examaples https://github.com/elastic/apm-pipeline-library/blob/master/resources/github-comment-markdown.template -->

<%if (statusSuccess) {%>
## :green_heart: Build Succeeded
<%} else if (buildStatus?.equals('ABORTED')) {%>
## :grey_exclamation: Build Aborted
<%if (!build?.description != null && build?.description.toString().toLowerCase().contains('aborted')) {%>
> There is a new build on-going so the previous on-going builds have been aborted.
<%} else if (!build?.description != null && build?.description.toString().toLowerCase().contains('allowed')) {%>
> ${build.description}
<%} else {%>
> Either there was a build timeout or someone aborted the build.'}
<%}%>
<%} else {%>
## :broken_heart: ${(testsSummary?.failed != 0) ? 'Tests Failed' : 'Build Failed'}
<%}%>

<!-- TEST RESULTS IF ANY-->
<% if(testsErrors?.any{item -> item?.status == "FAILED"}) {%>
### Test errors [![${testsSummary?.failed}](https://img.shields.io/badge/${testsSummary?.failed}%20-red)](${jobUrl}/tests)
<details><summary>Expand to view the tests failures</summary><p>
${(testsSummary?.failed > 10) ? '> Show only the first 10 test failures' : ''}
<% testsErrors?.findAll{item -> item?.status == "FAILED"}?.take(10)?.each { test -> %>
##### `${test?.name}`
<% errorDetails = (test?.errorDetails && !test?.errorDetails?.equals('null')) ? "<details><summary>Expand to view the error details</summary><p>\n\n```\n ${test?.errorDetails} \n ```\n</p></details>" : '<li>no error details</li>'%>
<% errorStackTrace = (test?.errorStackTrace && !test?.errorStackTrace?.equals('null')) ? "<details><summary>Expand to view the stacktrace</summary><p>\n\n```\n ${test?.errorStackTrace} \n ```\n</p></details>" : '<li>no stacktrace</li>'%>
<ul>
${errorDetails}
${errorStackTrace}
</ul>
<%}%>
</p></details>
<%}%>

<!-- STEPS ERRORS IF ANY -->
<% errorGitHub = stepsErrors?.find{it?.result == "FAILURE" && it?.displayName?.contains('Notifies GitHub')}%>
<% errorDeleteDir = stepsErrors?.find{it?.result == "FAILURE" && it?.displayName?.contains('Recursively delete the current directory from the workspace')}%>
<% stepsErrors = stepsErrors?.findAll{it?.result == "FAILURE" && !it?.displayName?.contains('Notifies GitHub') && !it?.displayName?.contains('Archive JUnit') && !it?.displayName?.contains('Recursively delete the current directory from the workspace')}%>
<% errorSignal = stepsErrors?.find{it?.displayName?.contains('Error signal')}%>
<% stepsErrors = stepsErrors?.findAll{ !it?.displayName?.contains('Error signal') } %>
<% if (errorSignal) { stepsErrors = stepsErrors << errorSignal }%>
<% if (errorDeleteDir) { stepsErrors = stepsErrors << errorDeleteDir }%>
<% if (stepsErrors?.size() <= 0 && !buildStatus?.equals('SUCCESS') && errorGitHub) {%>
<% stepsErrors = stepsErrors << errorGitHub %>
<%}%>
<% if (stepsErrors?.size() != 0 && !statusSuccess) {%>
### Steps errors [![${stepsErrors?.size()}](https://img.shields.io/badge/${stepsErrors?.size()}%20-red)](${jobUrl}/pipeline)
<% if (stepsErrors?.size() > 10) {%>
> Show only the first 10 steps failures
<% }%>
<% stepsErrors?.takeRight(10)?.each{ c -> %>
<% description = (c?.displayDescription && c?.displayDescription != 'null') ? "<li>Description: <code>${c?.displayDescription}</code></l1>" : ''%>
<% url = (c?.url && c?.url != 'null') ? ". View more details on <a href=\"${c?.url}/?start=0\">here</a>" : ''%>
##### `${c?.displayName && c?.displayName != 'null' ? c?.displayName.replaceAll('\\n', '') : ''}`
<ul>
<li>${url}</li>
${description}
</ul>
<%}%>
<%}%>
1 change: 1 addition & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ VERSION=${env.VERSION}-SNAPSHOT""")
// Required to enable the flaky test reporting with GitHub. Workspace exists since the post/always runs earlier
dir("${BASE_DIR}"){
notifyBuildResult(prComment: true,
buildCommentTemplate: '.ci/github-comment.template',
slackComment: true, slackNotify: (isBranch() || isTag()),
analyzeFlakey: !isTag(), jobName: getFlakyJobName(withBranch: getFlakyBranch()))
}
Expand Down

0 comments on commit 6bcaf13

Please sign in to comment.