From d2ee37a3e09715748a43ee45909ae6367b863a61 Mon Sep 17 00:00:00 2001 From: Grant Limberg <grant.limberg@zerotier.com> Date: Tue, 25 Oct 2016 14:58:27 -0700 Subject: [PATCH] attempting to add the changelog to the starting build slack message --- Jenkinsfile | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index d4f2e9192..55da43efa 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,6 +1,9 @@ #!/usr/bin/env groovy -slackSend "Building ${env.JOB_NAME} #${env.BUILD_NUMBER}" +passedBuilds = [] +def changelog = lastSuccessfulBuild(passedBuilds, currentBuild) + +slackSend "Building ${env.JOB_NAME} #${env.BUILD_NUMBER} \n ${changelog}" parallel 'centos7': { node('centos7') { try { @@ -55,4 +58,28 @@ parallel 'centos7': { } } -slackSend "${env.JOB_NAME} #${env.BUILD_NUMBER} Complete (<${env.BUILD_URL}|Show More...>)" \ No newline at end of file +slackSend "${env.JOB_NAME} #${env.BUILD_NUMBER} Complete (<${env.BUILD_URL}|Show More...>)" + +def lastSuccessfulBuild(passedBuilds, build) { + if ((build != null) && (build.result != 'SUCCESS')) { + passedBuilds.add(build) + lastSuccessfulBuild(passedBuilds, build.getPreviousBuild()) + } +} + +@NonCPS +def getChangeLog(passedBuilds) { + def log = "" + for (int x = 0; x < passedBuilds.size(); x++) { + def currentBuild = passedBuilds[x]; + def changeLogSets = currentBuild.rawBuild.changeSets + for (int i = 0; i < changeLogSets.size(); i++) { + def entries = changeLogSets[i].items + for (int j = 0; j < entries.length; j++) { + def entry = entries[j] + log += "* ${entry.msg} by ${entry.author} \n" + } + } + } + return log; +} \ No newline at end of file