mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-21 23:05:50 +00:00
testing slack notification
This commit is contained in:
parent
77b8b30033
commit
08e6477f96
1 changed files with 47 additions and 21 deletions
66
Jenkinsfile
vendored
66
Jenkinsfile
vendored
|
@ -1,31 +1,57 @@
|
||||||
pipeline {
|
node {
|
||||||
agent any
|
try {
|
||||||
stages {
|
notifyBuild('STARTED')
|
||||||
stage('Build') {
|
|
||||||
steps {
|
stage('Prepare code') {
|
||||||
bat 'mvn clean'
|
echo 'do checkout stuff'
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Testing') {
|
stage('Testing') {
|
||||||
steps {
|
echo 'Testing'
|
||||||
bat 'mvn test'
|
echo 'Testing - publish coverage results'
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Package') {
|
stage('Staging') {
|
||||||
steps {
|
echo 'Deploy Stage'
|
||||||
bat 'mvn package'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Deploy') {
|
stage('Deploy') {
|
||||||
when{
|
echo 'Deploy - Backend'
|
||||||
branch 'master'
|
echo 'Deploy - Frontend'
|
||||||
}
|
|
||||||
steps {
|
|
||||||
bat 'mvn deploy'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
// If there was an exception thrown, the build failed
|
||||||
|
currentBuild.result = "FAILED"
|
||||||
|
throw e
|
||||||
|
} finally {
|
||||||
|
// Success or failure, always send notifications
|
||||||
|
notifyBuild(currentBuild.result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def notifyBuild(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)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue