diff --git a/resources/github-comment-markdown.template b/resources/github-comment-markdown.template index 2f0efc40e..9496233a1 100644 --- a/resources/github-comment-markdown.template +++ b/resources/github-comment-markdown.template @@ -81,10 +81,12 @@ ${errorStackTrace} <% errorGitHub = stepsErrors?.find{it?.result == "FAILURE" && it?.displayName?.contains('Notifies GitHub')}%> -<% stepsErrors = stepsErrors?.findAll{it?.result == "FAILURE" && !it?.displayName?.contains('Notifies GitHub') && !it?.displayName?.contains('Archive JUnit')}%> +<% 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 %> <%}%> diff --git a/src/test/groovy/ApmBasePipelineTest.groovy b/src/test/groovy/ApmBasePipelineTest.groovy index f9659a3a2..7bd4e9a8e 100644 --- a/src/test/groovy/ApmBasePipelineTest.groovy +++ b/src/test/groovy/ApmBasePipelineTest.groovy @@ -620,6 +620,14 @@ class ApmBasePipelineTest extends DeclarativePipelineTest { } } + def assertMethodCallContainsPatternOccurrences(String methodName, String pattern, int compare) { + return helper.callStack.findAll { call -> + call.methodName == methodName + }.any { call -> + ((callArgsToString(call) =~ /${pattern}/).count) == compare + } + } + def assertMethodCall(String methodName) { return helper.callStack.find { call -> call.methodName == methodName diff --git a/src/test/groovy/NotificationManagerStepTests.groovy b/src/test/groovy/NotificationManagerStepTests.groovy index 4b735c0f5..aeaaca22b 100644 --- a/src/test/groovy/NotificationManagerStepTests.groovy +++ b/src/test/groovy/NotificationManagerStepTests.groovy @@ -426,6 +426,25 @@ class NotificationManagerStepTests extends ApmBasePipelineTest { assertJobStatusSuccess() } + @Test + void test_notify_pr_with_failure_and_deleteDir_issues() throws Exception { + script.notifyPR( + build: readJSON(file: "build-info.json"), + buildStatus: "FAILURE", + changeSet: readJSON(file: "changeSet-info.json"), + log: f.getText(), + statsUrl: "https://ecs.example.com/app/kibana", + stepsErrors: readJSON(file: "steps-errors-with-deleteDir-issue.json"), + testsErrors: [], + testsSummary: readJSON(file: "tests-summary.json") + ) + printCallStack() + assertTrue(assertMethodCallContainsPattern('githubPrComment', 'Build Failed')) + assertTrue(assertMethodCallContainsPattern('githubPrComment', 'Shell Script')) + assertTrue(assertMethodCallContainsPatternOccurrences('githubPrComment', 'Recursively delete the current directory from the workspace', 1)) + assertJobStatusSuccess() + } + @Test void test_notify_pr_with_a_generated_comment() throws Exception { script.notifyPR(comment: 'My Comment') diff --git a/src/test/resources/steps-errors-with-deleteDir-issue.json b/src/test/resources/steps-errors-with-deleteDir-issue.json new file mode 100644 index 000000000..77f17b8af --- /dev/null +++ b/src/test/resources/steps-errors-with-deleteDir-issue.json @@ -0,0 +1,50 @@ +[ + { + "displayDescription": "Unable to delete 'C:\\Users\\jenkins\\workspace\\Beats_beats_PR-22662'. Tried 3 times (of a maximum of 3", + "displayName": "Recursively delete the current directory from the workspace", + "durationInMillis": 270827, + "id": "12168", + "input": null, + "result": "FAILURE", + "startTime": "2021-02-18T16:23:33.466+0000", + "state": "FINISHED", + "type": "STEP", + "url": "https://beats-ci.elastic.co//blue/rest/organizations/jenkins/pipelines/Beats/pipelines/beats/pipelines/PR-22662/runs/3/steps/12168/log" + }, + { + "displayDescription": "Unable to delete 'C:\\Users\\jenkins\\workspace\\Beats_beats_PR-22662'. Tried 3 times (of a maximum of 3", + "displayName": "Recursively delete the current directory from the workspace", + "durationInMillis": 282224, + "id": "11714", + "input": null, + "result": "FAILURE", + "startTime": "2021-02-18T16:22:37.478+0000", + "state": "FINISHED", + "type": "STEP", + "url": "https://beats-ci.elastic.co//blue/rest/organizations/jenkins/pipelines/Beats/pipelines/beats/pipelines/PR-22662/runs/3/steps/11714/log" + }, + { + "displayDescription": "Unable to delete 'C:\\Users\\jenkins\\workspace\\Beats_beats_PR-22662'. Tried 3 times (of a maximum of 3", + "displayName": "Recursively delete the current directory from the workspace", + "durationInMillis": 193494, + "id": "12939", + "input": null, + "result": "FAILURE", + "startTime": "2021-02-18T16:24:40.836+0000", + "state": "FINISHED", + "type": "STEP", + "url": "https://beats-ci.elastic.co//blue/rest/organizations/jenkins/pipelines/Beats/pipelines/beats/pipelines/PR-22662/runs/3/steps/12939/log" + }, + { + "displayDescription": null, + "displayName": "Shell Script", + "durationInMillis": 101825, + "id": "58", + "input": null, + "result": "FAILURE", + "startTime": "2021-02-18T16:24:40.836+0000", + "state": "FINISHED", + "type": "STEP", + "url": "https://beats-ci.elastic.co//blue/rest/organizations/jenkins/pipelines/Beats/pipelines/beats/pipelines/PR-22662/runs/3/steps/58/log" + } +]