From e0489a8488f4412a4d081d233470797cec187b7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85ke=20Forslund?= Date: Sun, 17 Jan 2021 21:52:17 +0100 Subject: [PATCH] Add update comment logic to Jenkins --- Jenkinsfile | 54 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 10 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index be7ea9d8fa..bbc124bc0d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -120,16 +120,33 @@ pipeline { } failure { script { + def comment_text = 'Voight Kampff Integration Test Failed ([Results](https://reports.mycroft.ai/core/' + env.BRANCH_ALIAS + ')). ' + + '\nMycroft logs are also available: ' + + '[skills.log](https://reports.mycroft.ai/core/' + env.BRANCH_ALIAS + '/logs/skills.log), ' + + '[audio.log](https://reports.mycroft.ai/core/' + env.BRANCH_ALIAS + '/logs/audio.log), ' + + '[voice.log](https://reports.mycroft.ai/core/' + env.BRANCH_ALIAS + '/logs/voice.log), ' + + '[bus.log](https://reports.mycroft.ai/core/' + env.BRANCH_ALIAS + '/logs/bus.log), ' + + '[enclosure.log](https://reports.mycroft.ai/core/' + env.BRANCH_ALIAS + '/logs/enclosure.log)' + // Create comment for Pull Requests if (env.CHANGE_ID) { - echo 'Sending PR comment' - pullRequest.comment('Voight Kampff Integration Test Failed ([Results](https://reports.mycroft.ai/core/' + env.BRANCH_ALIAS + ')). ' + - '\nMycroft logs are also available: ' + - '[skills.log](https://reports.mycroft.ai/core/' + env.BRANCH_ALIAS + '/logs/skills.log), ' + - '[audio.log](https://reports.mycroft.ai/core/' + env.BRANCH_ALIAS + '/logs/audio.log), ' + - '[voice.log](https://reports.mycroft.ai/core/' + env.BRANCH_ALIAS + '/logs/voice.log), ' + - '[bus.log](https://reports.mycroft.ai/core/' + env.BRANCH_ALIAS + '/logs/bus.log), ' + - '[enclosure.log](https://reports.mycroft.ai/core/' + env.BRANCH_ALIAS + '/logs/enclosure.log)') + def found_comment = false + for (comment in pullRequest.comments) { + echo "Author: ${comment.user}" + if (comment.user == "devops-mycroft" && + comment.body.contains("Voight Kampff")) { + echo "Updating comment..." + found_comment = true + pullRequest.editComment( + comment.id, + comment_text + ) + } + } + if (!found_comment) { + echo 'Sending PR comment' + pullRequest.comment(comment_text) + } } } // Send failure email containing a link to the Jenkins build @@ -184,8 +201,25 @@ pipeline { success { script { if (env.CHANGE_ID) { - echo 'Sending PR comment' - pullRequest.comment('Voight Kampff Integration Test Succeeded ([Results](https://reports.mycroft.ai/core/' + env.BRANCH_ALIAS + '))') + def comment_text = 'Voight Kampff Integration Test Succeeded ([Results](https://reports.mycroft.ai/core/' + env.BRANCH_ALIAS + '))' + def found_comment = false + for (comment in pullRequest.comments) { + echo "Author: ${comment.user}" + if (comment.user == "devops-mycroft" && + comment.body.contains("Voight Kampff")) { + echo "Updating comment!" + found_comment = true + pullRequest.editComment( + comment.id, + comment_text + ) + break + } + } + if (!found_comment) { + echo 'Sending PR comment' + pullRequest.comment(comment_text) + } } } // Send success email containing a link to the Jenkins build