Skip to content

Commit

Permalink
Update notify code
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Iranzo Gómez <Pablo.Iranzo@gmail.com>
  • Loading branch information
iranzo committed Nov 7, 2019
1 parent 41bb1dc commit b1b9eea
Showing 1 changed file with 15 additions and 25 deletions.
40 changes: 15 additions & 25 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,19 @@ def cloudEnvironments = [
// ]
]

def notifyBuild(String environment = '', String buildStatus = 'STARTED') {
// build status of null means successful
buildStatus = buildStatus ?: 'SUCCESSFUL'

// Default values
def colorName = 'RED'
def colorCode = '#FF0000'
def subject = "${environment} : ${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)
// define the slack notify build function
def notifyBuild(String environment = '', def buildStatus) {

// set default of build status
buildStatus = buildStatus ?: 'SUCCESS'
def colorMap = [ 'STARTED': '#FFA500', 'SUCCESS': '#008B00', 'FAILURE': '#FF0000' ]

// Define messages contents
def subject = "Pipeline: ${environment} : #${env.BUILD_NUMBER} ${buildStatus}"
def summary = "${subject} (${env.BUILD_URL})"
def colorName = colorMap[buildStatus]

slackSend (color: colorName, message: summary)
}

builders = [:]
Expand Down Expand Up @@ -102,6 +91,7 @@ cloudEnvironments.each { environName, environValues ->
handlePipelineStep {

echo "STARTING TESTS FOR ${environName}"
notifyBuild("${environName}", 'STARTED')

// Clone this git repo into the container so that included scripts can be ran.
checkout scm
Expand Down Expand Up @@ -132,7 +122,7 @@ cloudEnvironments.each { environName, environValues ->
}

} catch (e) {

currentBuild.result = "FAILED"
echo e.toString()
throw e.toString()

Expand Down

0 comments on commit b1b9eea

Please sign in to comment.