Skip to content

Commit

Permalink
Add possibility slacking of failed builds
Browse files Browse the repository at this point in the history
Signed-off-by: mnokka-unikie <[email protected]>
  • Loading branch information
mnokka-unikie committed Jun 26, 2024
1 parent 9229211 commit 71774a6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 45 deletions.
22 changes: 6 additions & 16 deletions 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 @@ -40,25 +40,15 @@ pipeline {
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: 'echo ${JENKINS_URL}', returnStdout: true).trim()
if (env.SERVER_NAME == "") {
env.SERVER_NAME = sh(script: 'uname -n', returnStdout: true).trim()
}
def slacking=utils.determine_environment(env.SERVER_NAME)
env.SERVER_ENVIRONMENT=slacking.env
env.SERVER_SLACK_CHANNEL=slacking.channel
if (env.SERVER_SLACK_CHANNEL == "FALSE") {
env.SLACK_FLAG = "FALSE"
}
else {
env.SLACK_FLAG = "TRUE"
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 "Server environment:${env.SERVER_ENVIRONMENT}"
echo "Slack channel:${env.SERVER_SLACK_CHANNEL}"
echo "Slacking status:${env.SLACK_FLAG}"
}
}
stage('Build x86_64') {
Expand Down Expand Up @@ -90,7 +80,7 @@ pipeline {
post {
failure {
script {
if (env.SLACK_FLAG== 'TRUE') {
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}",
Expand Down
22 changes: 6 additions & 16 deletions 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 @@ -46,25 +46,15 @@ pipeline {
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: 'echo ${JENKINS_URL}', returnStdout: true).trim()
if (env.SERVER_NAME == "") {
env.SERVER_NAME = sh(script: 'uname -n', returnStdout: true).trim()
}
def slacking=utils.determine_environment(env.SERVER_NAME)
env.SERVER_ENVIRONMENT=slacking.env
env.SERVER_SLACK_CHANNEL=slacking.channel
if (env.SERVER_SLACK_CHANNEL == "FALSE") {
env.SLACK_FLAG = "FALSE"
}
else {
env.SLACK_FLAG = "TRUE"
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 "Server environment:${env.SERVER_ENVIRONMENT}"
echo "Slack channel:${env.SERVER_SLACK_CHANNEL}"
echo "Slacking status:${env.SLACK_FLAG}"
}
}
stage('Build x86_64') {
Expand Down Expand Up @@ -145,7 +135,7 @@ pipeline {
post {
failure {
script {
if (env.SLACK_FLAG== 'TRUE') {
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}",
Expand Down
13 changes: 0 additions & 13 deletions utils.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,6 @@ def find_img_relpath(String flakeref, String subdir) {
return imgdir
}

def determine_environment(serverName) {
def DEV_SLACK_CHANNEL = "ghaf-jenkins-builds-failed"
def PROD_SLACK_CHANNEL = "FALSE" // no slacking
def PRIVATE_SLACK_CHANNEL = "ghaf-jenkins-ci"
if (serverName.contains('prod')) {
return [env: 'prod', channel:PROD_SLACK_CHANNEL ]
} else if (serverName.contains('dev')) {
return [env: 'dev', channel:DEV_SLACK_CHANNEL ]
} else {
return [env:'priv', channel:PRIVATE_SLACK_CHANNEL ]
}
}

return this

////////////////////////////////////////////////////////////////////////////////

0 comments on commit 71774a6

Please sign in to comment.