From f911895b11281d88d792762270ce9ce7a42ff85a Mon Sep 17 00:00:00 2001
From: Raphael Defosseux <raphael.defosseux@eurecom.fr>
Date: Tue, 24 Jul 2018 12:32:33 +0200
Subject: [PATCH] CI: added abstraction layer to social messaging   -- a
 boolean parameter should be added to master eNB job   -- for slack:
 pipelineUsesSlack      if not present or false, no message will be sent

Signed-off-by: Raphael Defosseux <raphael.defosseux@eurecom.fr>
---
 ci-scripts/Jenkinsfile-gitlab | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/ci-scripts/Jenkinsfile-gitlab b/ci-scripts/Jenkinsfile-gitlab
index 3c72e64d77a..73d13732f3d 100644
--- a/ci-scripts/Jenkinsfile-gitlab
+++ b/ci-scripts/Jenkinsfile-gitlab
@@ -1,3 +1,4 @@
+#!/bin/groovy
 /*
  * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
  * contributor license agreements.  See the NOTICE file distributed with
@@ -19,6 +20,16 @@
  *      contact@openairinterface.org
  */
 
+// Abstraction function to send social media messages:
+// like on Slack or Mattermost
+def sendSocialMediaMessage(pipeChannel, pipeColor, pipeMessage) {
+    if (params.pipelineUsesSlack != null) {
+        if (params.pipelineUsesSlack) {
+            slackSend channel: pipeChannel, color: pipeColor, message: pipeMessage
+        }
+    }
+}
+
 pipeline {
     agent {
         label 'bellatrix'
@@ -229,9 +240,9 @@ pipeline {
                     echo "This is a MERGE event"
                     addGitLabMRComment comment: message
                     def message2 = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): passed (" + BUILD_URL + ") -- MergeRequest #" + env.gitlabMergeRequestIid + " (" + env.gitlabMergeRequestTitle + ")"
-                    slackSend channel: 'ci-enb', color: 'good', message: message2
+                    sendSocialMediaMessage('ci-enb', 'good', message2)
                 } else {
-                    slackSend channel: 'ci-enb', color: 'good', message: message
+                    sendSocialMediaMessage('ci-enb', 'good', message)
                 }
             }
         }
@@ -242,9 +253,9 @@ pipeline {
                     echo "This is a MERGE event"
                     addGitLabMRComment comment: message
                     def message2 = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): failed (" + BUILD_URL + ") -- MergeRequest #" + env.gitlabMergeRequestIid + " (" + env.gitlabMergeRequestTitle + ")"
-                    slackSend channel: 'ci-enb', color: 'danger', message: message2
+                    sendSocialMediaMessage('ci-enb', 'danger', message2)
                 } else {
-                    slackSend channel: 'ci-enb', color: 'danger', message: message
+                    sendSocialMediaMessage('ci-enb', 'danger', message)
                 }
             }
         }
-- 
GitLab