pipeline { ... MUNCH ... stage('Update Jira') { steps { echo 'Update Jira' commentJiraIssues() } } } @NonCPS void commentJiraIssues() { echo "commentJiraIssues" def issue_pattern = "(OG|OGSD|OHD)-\\d+" // Find all relevant commit ids currentBuild.changeSets.each {changeSet -> changeSet.each { commit -> echo "... ping" echo "... commit: "+commit String commitId = commit.getCommitId() String msg = commit.getMsg() echo "testing commit: "+msg msg.findAll(issue_pattern).each {id -> echo "issue: "+id def ts = new Date(commit.getTimestamp()) // Actually post a comment def response = jiraAddComment( idOrKey: id, site: "iwjira", comment: "[JENKINS-PIPELINE]\n"+ "Current Build: "+ currentBuild.absoluteUrl+"\n"+ "Git Commit ID: ${env.GITREPO_HOST_URL}/scm/#changesetPanel;${env.GITREPO_BRANCH};"+commitId+"\n"+ "Commit Message: "+msg+"\n"+ "Author: "+commit.getAuthor().getFullName()+"\n"+ "Timestamp: "+ts.format("yyyyMMdd.HHmmss", TimeZone.getTimeZone('UTC'))+" UTC\n"+ "Files: "+commit.getAffectedPaths(), failOnError: false, auditLog: false ) echo "... after add" } echo "... after findAll" } } // If we get here, we know that *THIS* build is successful // test previousBuilds and relate all info for past // unsuccessful builds echo "testing previous builds" echo "currentBuild is: "+currentBuild def run = currentBuild.previousBuild echo "run is: "+run while (run != null) { echo "evaluating run: "+run.number+", "+run.currentResult if (run.resultIsWorseOrEqualTo("UNSTABLE")) { echo "worse than success" run.changeSets.each {changeSet -> changeSet.each { commit -> echo "... ping" echo "... commit: "+commit String commitId = commit.getCommitId() String msg = commit.getMsg() echo "...testing commit: "+msg msg.findAll(issue_pattern).each { id -> echo "issue: "+id def ts = new Date(commit.getTimestamp()) // post the comment def response = jiraAddComment( idOrKey: id, site: "iwjira", comment: "[JENKINS-PIPELINE]\n"+ "Current Build: "+ currentBuild.absoluteUrl+"\n"+ "Git Commit ID: ${env.GITREPO_HOST_URL}/scm/#changesetPanel;${env.GITREPO_BRANCH};"+commitId+"\n"+ "Commit Message: "+msg+"\n"+ "Author: "+commit.getAuthor().getFullName()+"\n"+ "Timestamp: "+ts.format("yyyyMMdd.HHmmss", TimeZone.getTimeZone('UTC'))+" UTC\n"+ "Files: "+commit.getAffectedPaths(), failOnError: false, auditLog: false ) echo "... after add" } echo "... after findAll" } } echo "end of commits for run" // iterate run = run.previousBuild echo "run is now: "+run } else { echo "was successful - ending loop" // break out of loop run = null } } echo "done with previous builds" }