diff --git a/ghaf-main-pipeline.groovy b/ghaf-main-pipeline.groovy index f68f9f2..8c544f2 100644 --- a/ghaf-main-pipeline.groovy +++ b/ghaf-main-pipeline.groovy @@ -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']], @@ -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') { @@ -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!" + } + } + } + } } //////////////////////////////////////////////////////////////////////////////// diff --git a/ghaf-nightly-pipeline.groovy b/ghaf-nightly-pipeline.groovy index e16c08f..54881a6 100644 --- a/ghaf-nightly-pipeline.groovy +++ b/ghaf-nightly-pipeline.groovy @@ -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']], @@ -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') { @@ -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!" + } + } + } + } } ////////////////////////////////////////////////////////////////////////////////