Skip to content

Instantly share code, notes, and snippets.

@aaukhatov
Last active June 8, 2017 10:50
Show Gist options
  • Save aaukhatov/0d53ba6d25ee20e27b06b901429d0bff to your computer and use it in GitHub Desktop.
Save aaukhatov/0d53ba6d25ee20e27b06b901429d0bff to your computer and use it in GitHub Desktop.
Email sender from Jenkins CI
node() {
stage("Checkout") {
cloneRepo("WSAlameda", "http://gitlabsvr.nsd.ru/gitlab/alameda/WSAlameda.git", "${branch}")
}
stage("Unit tests") {
dir('WSAlameda') {
try {
sh "chmod +x gradlew"
sh(script: './gradlew clean test')
} catch (Exception e) {
currentBuild.result = 'FAILURE'
}
}
}
stage("Publish reports") {
println 'publish junit report'
try {
junit 'WSAlameda/build/test-results/TEST-*.xml'
println 'send emails'
if (currentBuild.result == 'FAILURE') {
sendUnitTestErrorEmail()
}
} catch (Exception e) {
sendUnitTestErrorEmail()
}
}
}
def cloneRepo(def targetDir, def gitUrl, def branch) {
checkout([$class: 'GitSCM', branches: [[name: '*/' + branch]], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: targetDir]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'TA_Builder', url: gitUrl]]])
}
def sendUnitTestErrorEmail() {
emailext(body: '${JELLY_SCRIPT,template="static-analysis"}', mimeType: 'text/html', subject: "WSAlameda. Юнит тесты не проходят. Билд: ${currentBuild.id}", recipientProviders: [[$class: 'CulpritsRecipientProvider'], [$class: 'DevelopersRecipientProvider']], to: "Toporova.AI@nsd.ru", attachLog: false)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment