Skip to content

Commit

Permalink
Merge pull request #356 from compucorp/staging
Browse files Browse the repository at this point in the history
Sync master with staging
  • Loading branch information
mickadoo authored May 1, 2018
2 parents ca84e96 + bbf8411 commit c33931d
Show file tree
Hide file tree
Showing 54 changed files with 2,032 additions and 2,352 deletions.
69 changes: 55 additions & 14 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pipeline {
stages {
stage('Pre-tasks execution') {
steps {
sendBuildStartdNotification()
sendBuildStartNotification()

// Print all Environment variables
sh 'printenv | sort'
Expand Down Expand Up @@ -161,26 +161,34 @@ pipeline {
/*
* Sends a notification when the build starts
*/
def sendBuildStartdNotification() {
def message = 'Building ' + getBuildTargetLink() + '. ' + getReportLink()
def sendBuildStartNotification() {
def msgHipChat = 'Building ' + getBuildTargetLink('hipchat') + '. ' + getReportLink('hipchat')
def msgSlack = 'Building ' + getBuildTargetLink('slack') + '. ' + getReportLink('slack')

sendHipchatNotification('YELLOW', message)
sendHipchatNotification('YELLOW', msgHipChat)
sendSlackNotification('warning', msgSlack)
}

/*
* Sends a notification when the build is completed successfully
*/
def sendBuildSuccessNotification() {
def message = getBuildTargetLink() + ' built successfully. Time: $BUILD_DURATION. ' + getReportLink()
sendHipchatNotification('GREEN', message)
def msgHipChat = getBuildTargetLink('hipchat') + ' built successfully. Time: $BUILD_DURATION. ' + getReportLink('hipchat')
def msgSlack = getBuildTargetLink('slack') + ' built successfully. Time: ' + getBuildDuration(currentBuild) + '. ' + getReportLink('slack')

sendHipchatNotification('GREEN', msgHipChat)
sendSlackNotification('good', msgSlack)
}

/*
* Sends a notification when the build fails
*/
def sendBuildFailureNotification() {
def message = 'Failed to build ' + getBuildTargetLink() + '. Time: $BUILD_DURATION. No. of failed tests: ${TEST_COUNTS,var=\"fail\"}. ' + getReportLink()
sendHipchatNotification('RED', message)
def msgHipChat = 'Failed to build ' + getBuildTargetLink('hipchat') + '. Time: $BUILD_DURATION. No. of failed tests: ${TEST_COUNTS,var=\"fail\"}. ' + getReportLink('hipchat')
def msgSlack = 'Failed to build ' + getBuildTargetLink('slack') + '. Time: ' + getBuildDuration(currentBuild) + '. ' + getReportLink('slack')

sendHipchatNotification('RED', msgHipChat)
sendSlackNotification('danger', msgSlack)
}

/*
Expand All @@ -190,16 +198,38 @@ def sendHipchatNotification(String color, String message) {
hipchatSend color: color, message: message, notify: true
}

/*
* Sends a notification to Slack
*/
def sendSlackNotification(String color, String message) {
slackSend color: color, message: message, notify: true
}

/*
* Returns the build duration without the "and counting" suffix
*/
def getBuildDuration(build) {
return build.durationString.replace(' and counting', '')
}

/*
* Returns a link to what is being built. If it's a PR, then it's a link to the pull request itself.
* If it's a branch, then it's a link in the format http://github.com/org/repo/tree/branch
*/
def getBuildTargetLink() {
if(buildIsForAPullRequest()) {
return "<a href=\"${env.CHANGE_URL}\">\"${env.CHANGE_TITLE}\"</a>"
def getBuildTargetLink(String client) {
def link = ''
def forPR = buildIsForAPullRequest()

switch (client) {
case 'hipchat':
link = forPR ? "<a href=\"${env.CHANGE_URL}\">\"${env.CHANGE_TITLE}\"</a>" : '<a href="' + getRepositoryUrlForBuildBranch() + '">"' + env.BRANCH_NAME + '"</a>'
break;
case 'slack':
link = forPR ? "<${env.CHANGE_URL}|${env.CHANGE_TITLE}>" : '<' + getRepositoryUrlForBuildBranch() + '|' + env.BRANCH_NAME + '>'
break;
}

return '<a href="' + getRepositoryUrlForBuildBranch() + '">"' + env.BRANCH_NAME + '"</a>'
return link
}

/*
Expand All @@ -222,8 +252,19 @@ def getRepositoryUrlForBuildBranch() {
/*
* Returns the Blue Ocean build report URL for the current job
*/
def getReportLink() {
return 'Click <a href="$BLUE_OCEAN_URL">here</a> to see the build report'
def getReportLink(String client) {
def link = ''

switch (client) {
case 'hipchat':
link = 'Click <a href="$BLUE_OCEAN_URL">here</a> to see the build report'
break
case 'slack':
link = "Click <${env.RUN_DISPLAY_URL}|here> to see the build report"
break
}

return link
}

def cloneRepositories(String envBranch) {
Expand Down
Loading

0 comments on commit c33931d

Please sign in to comment.