Skip to content

Instantly share code, notes, and snippets.

@FyberEngineers
Created March 5, 2020 09:20
Show Gist options
  • Select an option

  • Save FyberEngineers/5783f168aee54294fafd5ab1a36c9683 to your computer and use it in GitHub Desktop.

Select an option

Save FyberEngineers/5783f168aee54294fafd5ab1a36c9683 to your computer and use it in GitHub Desktop.
String branch = env.BRANCH_NAME.toString()
stage('Maven build') {
//returns a set of git revisions with the name of the committer
@NonCPS
def commitList = {
def changes = ""
currentBuild.changeSets.each { set ->
set.each { entry ->
changes += "${entry.commitId} - ${entry.msg} \n by ${entry.author.fullName}\n"
}
}
return changes
}
def handleFailures = {
if (branch.startsWith("ST-")) {
step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: emailextrecipients([[$class: 'RequesterRecipientProvider']]), sendToIndividuals: true])
} else {
step('Send notification') {
mail(to: 'server@fullgc.com',
subject: "Maven build failed for branch: " + env.BRANCH_NAME.toString(),
body: "last commits are: " + commitList().toString() + " (<$BUILD_URL/console|Job>)");
}
slackSend channel: 'server', color: 'warning', message: "Maven build failed for branch ${branch} \". \nlast Commits are: \n" + commitList().toString() + "\n (<$BUILD_URL/console|Job>)"
}
}
try {
withMaven(jdk: 'JDK 8 update 66', maven: 'Maven 3.0.5') {
sh "mvn -Dmaven.test.failure.ignore=true clean install"
}
if (currentBuild.result("UNSTABLE")) {
handleFailures()
}
} catch (Exception e) {
manager.buildFailure()
handleFailures()
throw e
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment