From f4a39043e2fb3da69e378b4e1cbcb4bd7e2a6662 Mon Sep 17 00:00:00 2001 From: Sean Busbey Date: Thu, 12 Apr 2018 21:10:53 -0500 Subject: [PATCH] HBASE-20388 nightly tests running on a feature branch should only comment on that feature branch's jira Signed-off-by: Mike Drob --- dev-support/Jenkinsfile | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/dev-support/Jenkinsfile b/dev-support/Jenkinsfile index 6e320cad2b1..821d20e6a89 100644 --- a/dev-support/Jenkinsfile +++ b/dev-support/Jenkinsfile @@ -528,8 +528,14 @@ curl -L -o personality.sh "${env.PROJECT_PERSONALITY}" echo "[INFO] Comment:" echo comment echo "" - echo "[INFO] There are ${currentBuild.changeSets.size()} change sets." - getJirasToComment(currentBuild).each { currentIssue -> + echo "[DEBUG] checking to see if feature branch" + def jiras = getJirasToComment(env.BRANCH_NAME, []) + if (jiras.isEmpty()) { + echo "[DEBUG] non-feature branch, checking change messages for jira keys." + echo "[INFO] There are ${currentBuild.changeSets.size()} change sets." + jiras = getJirasToCommentFromChangesets(currentBuild) + } + jiras.each { currentIssue -> jiraComment issueKey: currentIssue, body: comment } } catch (Exception exception) { @@ -542,7 +548,7 @@ curl -L -o personality.sh "${env.PROJECT_PERSONALITY}" } import org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper @NonCPS -List getJirasToComment(RunWrapper thisBuild) { +List getJirasToCommentFromChangesets(RunWrapper thisBuild) { def seenJiras = [] thisBuild.changeSets.each { cs -> cs.getItems().each { change -> @@ -552,16 +558,21 @@ List getJirasToComment(RunWrapper thisBuild) { echo " ${change.commitId}" echo " ${change.author}" echo "" - msg.eachMatch("HBASE-[0-9]+") { currentIssue -> - echo "[DEBUG] found jira key: ${currentIssue}" - if (currentIssue in seenJiras) { - echo "[DEBUG] already commented on ${currentIssue}." - } else { - echo "[INFO] commenting on ${currentIssue}." - seenJiras << currentIssue - } - } + seenJiras = getJirasToComment(msg, seenJiras) } } return seenJiras } +@NonCPS +List getJirasToComment(CharSequence source, List seen) { + source.eachMatch("HBASE-[0-9]+") { currentIssue -> + echo "[DEBUG] found jira key: ${currentIssue}" + if (currentIssue in seen) { + echo "[DEBUG] already commented on ${currentIssue}." + } else { + echo "[INFO] commenting on ${currentIssue}." + seen << currentIssue + } + } + return seen +}