Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add slacking for failed builds #33

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion ghaf-main-pipeline.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pipeline {
stages {
stage('Checkout') {
steps {
script { utils = load "utils.groovy" }
script { utils = load "/tmp/utils.groovy" }
dir(WORKDIR) {
checkout scmGit(
branches: [[name: 'main']],
Expand All @@ -39,8 +39,16 @@ pipeline {
script {
env.TARGET_COMMIT = sh(script: 'git rev-parse HEAD', returnStdout: true).trim()
env.ARTIFACTS_REMOTE_PATH = "${env.JOB_NAME}/build_${env.BUILD_ID}-commit_${env.TARGET_COMMIT}"
env.GITHUBLINK="https://github.com/tiiuae/ghaf/commit/${env.TARGET_COMMIT}"
env.SERVER_NAME = sh(script: 'uname -n', returnStdout: true).trim()
env.SERVER_SLACK_CHANNEL=""
if (env.SERVER_NAME=="ghaf-jenkins-controller-dev") {
env.SERVER_SLACK_CHANNEL="ghaf-jenkins-builds-failed"
}
}
}
echo "Server name:${env.SERVER_NAME}"
echo "Slack channel:${env.SERVER_SLACK_CHANNEL}"
}
}
stage('Build x86_64') {
Expand Down Expand Up @@ -68,6 +76,24 @@ pipeline {
}
}
}

post {
failure {
script {
if (env.SERVER_SLACK_CHANNEL != "") {
message= "FAIL build: ${env.SERVER_NAME} ${env.JOB_NAME} [${env.BUILD_NUMBER}] (<${env.GITHUBLINK}|The commits>) (<${env.BUILD_URL}|The Build>)"
slackSend (
channel: "${env.SERVER_SLACK_CHANNEL}",
color: '#36a64f', // green
message: message
)
}
else {
echo "Slack message not sent. Check pipeline slack configuration!"
}
}
}
}
}

////////////////////////////////////////////////////////////////////////////////
27 changes: 26 additions & 1 deletion ghaf-nightly-pipeline.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pipeline {
stages {
stage('Checkout') {
steps {
script { utils = load "utils.groovy" }
script { utils = load "/tmp/utils.groovy" }
dir(WORKDIR) {
checkout scmGit(
branches: [[name: 'main']],
Expand All @@ -45,8 +45,16 @@ pipeline {
env.TARGET_REPO = sh(script: 'git remote get-url origin', returnStdout: true).trim()
env.TARGET_COMMIT = sh(script: 'git rev-parse HEAD', returnStdout: true).trim()
env.ARTIFACTS_REMOTE_PATH = "${env.JOB_NAME}/build_${env.BUILD_ID}-commit_${env.TARGET_COMMIT}"
env.GITHUBLINK="https://github.com/tiiuae/ghaf/commit/${env.TARGET_COMMIT}"
env.SERVER_NAME = sh(script: 'uname -n', returnStdout: true).trim()
env.SERVER_SLACK_CHANNEL=""
if (env.SERVER_NAME=="ghaf-jenkins-controller-dev") {
env.SERVER_SLACK_CHANNEL="ghaf-jenkins-builds-failed"
}
}
}
echo "Server name:${env.SERVER_NAME}"
echo "Slack channel:${env.SERVER_SLACK_CHANNEL}"
}
}
stage('Build x86_64') {
Expand Down Expand Up @@ -124,6 +132,23 @@ pipeline {
}
}
}
post {
failure {
script {
if (env.SERVER_SLACK_CHANNEL != "") {
message= "FAIL build: ${env.SERVER_NAME} ${env.JOB_NAME} [${env.BUILD_NUMBER}] (<${env.GITHUBLINK}|The commits>) (<${env.BUILD_URL}|The Build>)"
slackSend (
channel: "${env.SERVER_SLACK_CHANNEL}",
color: '#36a64f', // green
message: message
)
}
else {
echo "Slack message not sent. Check pipeline slack configuration!"
}
}
}
}
}

////////////////////////////////////////////////////////////////////////////////
Loading