From 2e49a9bfb6f873c22474e66f9bdf9d6d7f1569e2 Mon Sep 17 00:00:00 2001 From: Jack-Leung <38930117+Jack-Leung@users.noreply.github.com> Date: Mon, 16 Mar 2020 09:32:41 -0400 Subject: [PATCH] adding slack notif --- Jenkinsfile | 71 +++++++++++++++++++++++------------------------------ 1 file changed, 31 insertions(+), 40 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index e9de95c04..ee972c046 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,48 +1,39 @@ pipeline { agent any stages { - script { - try { - notifySlack('STARTED') - - stage('Build') { - echo 'build' + stage('Build') { + steps { + bat 'mvn clean' } + } - } catch (e) { - // If there was an exception thrown, the build failed - currentBuild.result = "FAILED" - throw e - } finally { - // Success or failure, always send notifications - notifySlack(currentBuild.result) + stage('Testing') { + steps { + bat 'mvn test' } - } + } + + stage('Package') { + steps { + bat 'mvn package' + } + } + + stage('Deploy') { + when{ + branch 'master' + } + steps { + bat 'mvn deploy' + } + } + } + post{ + success{ + slackSend color: "good", message: "Success: ${env.JOB_NAME} ${env.BUILD_NUMBER} (<${env.BUILD_URL}|Open>)" + } + failure{ + slackSend color: "danger", message: "Failure: ${env.JOB_NAME} ${env.BUILD_NUMBER} (<${env.BUILD_URL}|Open>)" + } } } - -def notifySlack(String buildStatus = 'STARTED') { - // build status of null means successful - buildStatus = buildStatus ?: 'SUCCESSFUL' - - // Default values - def colorName = 'RED' - def colorCode = '#FF0000' - def subject = "${buildStatus}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'" - def summary = "${subject} (${env.BUILD_URL})" - - // Override default values based on build status - if (buildStatus == 'STARTED') { - color = 'YELLOW' - colorCode = '#FFFF00' - } else if (buildStatus == 'SUCCESSFUL') { - color = 'GREEN' - colorCode = '#00FF00' - } else { - color = 'RED' - colorCode = '#FF0000' - } - - // Send notifications - slackSend (color: colorCode, message: summary) -}