diff --git a/ghaf-main-pipeline.groovy b/ghaf-main-pipeline.groovy index 87b753a..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']], @@ -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') { @@ -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}", diff --git a/ghaf-nightly-pipeline.groovy b/ghaf-nightly-pipeline.groovy index 8bdcc72..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']], @@ -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') { @@ -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}", diff --git a/utils.groovy b/utils.groovy index 889b07d..75fe91b 100644 --- a/utils.groovy +++ b/utils.groovy @@ -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 ////////////////////////////////////////////////////////////////////////////////