Add Jenkinsfile 44/238944/6
authorKrzysztof Wieclaw <k.wieclaw@samsung.com>
Mon, 20 Jul 2020 15:22:35 +0000 (17:22 +0200)
committerKrzysztof Wieclaw <k.wieclaw@samsung.com>
Wed, 19 Aug 2020 15:49:24 +0000 (17:49 +0200)
Change-Id: I04df8f7c20fe4c51e14239bc1398c1dc0bc700ab
Signed-off-by: Krzysztof Wieclaw <k.wieclaw@samsung.com>
Jenkinsfile [new file with mode: 0644]
sam_cli.cfg [new file with mode: 0755]
sonar_build.sh [new file with mode: 0755]
svace_build.sh [new file with mode: 0755]

diff --git a/Jenkinsfile b/Jenkinsfile
new file mode 100644 (file)
index 0000000..93fe290
--- /dev/null
@@ -0,0 +1,205 @@
+pipeline {
+  agent {
+    docker {
+      image 'art.sec.samsung.net/tizenwearable_docker/ci:v0.18'
+      registryUrl 'https://art.sec.samsung.net/'
+      registryCredentialsId 'botoxcorp'
+    }
+  }
+  stages {
+    stage('Configure') {
+      steps {
+        script {
+          HTTP_SERVER = '106.120.130.80'
+          HTTP_PORT = '9000'
+          HTTP_BASE_URL_PATH = "http://${HTTP_SERVER}:${HTTP_PORT}"
+          HTTP_SAM_PATH = "sam/results"
+          HTTP_DOTNET_FORMAT_PATH = "dotnet-format"
+          HTTP_CLANG_FORMAT_PATH = "clang_format"
+          PROJECT_NAME = "Oobe"
+          SONAR_QUBE_RESULT_URL = 'https://sonar.sprc.samsung.pl/project/activity?id=TizenOobeIotCI'
+          SVACE_RESULT_URL = 'http://106.120.130.104:12000/sb2/main/review#PRJID=12&VIEWID=0'
+          SOLUTION_DIR = "Oobe"
+          SOLUTION_NAME = "Oobe.sln"
+          SOLUTION_PATH = "${SOLUTION_DIR}/${SOLUTION_NAME}"
+          GIT_COMMIT_REV = GIT_COMMIT
+          REPO_NAME = env.GIT_URL.tokenize("/")[-1].tokenize(".")[0]
+          REPO_OWNER = env.GIT_URL.tokenize("/")[-2]
+          if(BRANCH_NAME == "tizen")
+          {
+            MERGE_TYPE = ""
+            SONAR_ARGUMENT = "-m"
+          } else {
+            MERGE_TYPE = "PR"
+            SONAR_ARGUMENT = ""
+          }
+        }
+      }
+    }
+    stage('Compiling C# app') {
+      steps {
+        sh "dotnet restore --source https://tizen.myget.org/F/dotnet/api/v3/index.json ${SOLUTION_PATH} || true"
+        sh "dotnet clean ${SOLUTION_PATH}"
+        sh "dotnet restore --source https://tizen.myget.org/F/dotnet/api/v3/index.json ${SOLUTION_PATH} || true"
+        sh "dotnet build ${SOLUTION_PATH} --configuration Release"
+        sh "cp Oobe/Oobe/bin/Release/tizen80/*.tpk \"${WORKSPACE}\""
+      }
+    }
+    stage('Code checks') {
+      parallel {
+        stage('Dotnet format check') {
+          steps {
+            script {
+              def return_code = sh(script: "dotnet format --check --report dotnet-format-report ${SOLUTION_PATH}", returnStatus: true)
+              DOTNET_FORMAT_RESULT_CODE = return_code
+              withCredentials([usernamePassword(credentialsId: 'http_server_password', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
+                def user_host = "${USERNAME}@${HTTP_SERVER}"
+                def www_path = ""
+                if(BRANCH_NAME == "tizen") {
+                  www_path = "${HTTP_DOTNET_FORMAT_PATH}/${PROJECT_NAME}_dotnet_format_output/${BRANCH_NAME}"
+                }
+                else {
+                  www_path = "${HTTP_DOTNET_FORMAT_PATH}/${PROJECT_NAME}_dotnet_format_output/${BRANCH_NAME}/${GIT_COMMIT_REV}"
+                }
+                def path = "~/www/${www_path}"
+                if(BRANCH_NAME == "tizen") {
+                  sh "sshpass -p ${PASSWORD} ssh -o StrictHostKeychecking=no ${user_host} rm -rf \"${path}\""
+                }
+                sh "sshpass -p ${PASSWORD} ssh -o StrictHostKeychecking=no ${user_host} mkdir -p \"${path}\""
+                sh "sshpass -p ${PASSWORD} scp ${SOLUTION_DIR}/dotnet-format-report/format-report.json \"${user_host}:${path}\""
+                DOTNET_FORMAT_RESULT_URL="${HTTP_BASE_URL_PATH}/${www_path}/format-report.json"
+              }
+            }
+          }
+        }
+        stage('Clang format check') {
+          steps {
+            script {
+              def return_code = sh(script: 'run-clang-format.py -r --clang-format-executable clang-format-10 . > clang_format.diff', returnStatus: true)
+              CLANG_RESULT_CODE = return_code
+              if (return_code == 2)
+              {
+                sh "echo Clang format encountered trouble during execution"
+                currentBuild.result = 'UNSTABLE'
+              }
+              else if (return_code == 1)
+              {
+                sh "echo Clang format execution finished sucessfully - diffs were found"
+              }
+              else if (return_code == 0)
+              {
+                sh "echo Clang format execution - diffs were not found"
+              }
+              else
+              {
+                sh "echo Clang format exited with unknown error"
+                currentBuild.result = 'FAILURE'
+              }
+              withCredentials([usernamePassword(credentialsId: 'http_server_password', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
+                def user_host = "${USERNAME}@${HTTP_SERVER}"
+                def www_path = ""
+                if(BRANCH_NAME == "tizen") {
+                  www_path = "${HTTP_CLANG_FORMAT_PATH}/${PROJECT_NAME}_clang_format_output/${BRANCH_NAME}"
+                }
+                else {
+                  www_path = "${HTTP_CLANG_FORMAT_PATH}/${PROJECT_NAME}_clang_format_output/${BRANCH_NAME}/${GIT_COMMIT_REV}"
+                }
+                def path = "~/www/${www_path}"
+                if(BRANCH_NAME == "tizen") {
+                  sh "sshpass -p ${PASSWORD} ssh -o StrictHostKeychecking=no ${user_host} rm -rf \"${path}\""
+                }
+                sh "sshpass -p ${PASSWORD} ssh -o StrictHostKeychecking=no ${user_host} mkdir -p \"${path}\""
+                sh "sshpass -p ${PASSWORD} scp clang_format.diff \"${user_host}:${path}\""
+                CLANG_RESULT_URL="${HTTP_BASE_URL_PATH}/${www_path}/clang_format.diff"
+              }
+            }
+          }
+        }
+        stage('SAM analysis')
+        {
+          steps {
+            script {
+              sh 'sam_cli.sh ./sam_cli.cfg'
+              sh "zip -r ${PROJECT_NAME}_SAM.zip output"
+              archiveArtifacts("${PROJECT_NAME}_SAM.zip")
+              sh "cp output/html/*.html output/html/report.html"
+              sh "cp output/html/*.png output/html/result.png"
+              withCredentials([usernamePassword(credentialsId: 'http_server_password', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
+                def user_host = "${USERNAME}@${HTTP_SERVER}"
+                def www_path = ""
+                if(BRANCH_NAME == "tizen") {
+                  www_path = "${HTTP_SAM_PATH}/${PROJECT_NAME}_SAM_output/${BRANCH_NAME}"
+                }
+                else {
+                  www_path = "${HTTP_SAM_PATH}/${PROJECT_NAME}_SAM_output/${BRANCH_NAME}/${GIT_COMMIT_REV}"
+                }
+                def path = "~/www/${www_path}"
+                if(BRANCH_NAME == "tizen") {
+                  sh "sshpass -p ${PASSWORD} ssh -o StrictHostKeychecking=no ${user_host} rm -rf \"${path}\""
+                }
+                sh "sshpass -p ${PASSWORD} ssh -o StrictHostKeychecking=no ${user_host} mkdir -p \"${path}\""
+                sh "sshpass -p ${PASSWORD} scp -r output \"${user_host}:${path}\""
+                sh "sshpass -p ${PASSWORD} scp ${PROJECT_NAME}_SAM.zip \"${user_host}:${path}\""
+                SAM_RESULT_URL="${HTTP_BASE_URL_PATH}/${www_path}/output/html/report.html"
+              }
+            }
+          }
+        }
+      }
+    }
+    stage('SonarQube analysis')
+    {
+      steps {
+        sh "./sonar_build.sh ${SONAR_ARGUMENT}"
+      }
+    }
+    stage('Svace analysis')
+    {
+      steps {
+        script {
+          withCredentials([usernamePassword(credentialsId: 'botoxcorp', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
+            sh "./svace_build.sh \"${USERNAME}\" \"${PASSWORD}\""
+          }
+        }
+      }
+    }
+  }
+  post {
+    success {
+      archiveArtifacts(artifacts: '*.tpk', onlyIfSuccessful: true, fingerprint: true)
+      script {
+        if(MERGE_TYPE != "")
+        {
+          String comment_content = "" +
+          "Build for commit ${GIT_COMMIT_REV} (${MERGE_TYPE}) succeded. Jenkins CI returned:\\n" +
+          "- [**clang_format** code result: ${CLANG_RESULT_CODE}](${CLANG_RESULT_URL}),\\n" +
+          "- [**dotnet format** report (result code: ${DOTNET_FORMAT_RESULT_CODE})](${DOTNET_FORMAT_RESULT_URL}),\\n" +
+          "- [**SAM** analysis](${SAM_RESULT_URL}),\\n" +
+          "- [updated **SonarQube** build](${SONAR_QUBE_RESULT_URL}),\\n" +
+          "- [updated **SVACE** build.](${SVACE_RESULT_URL})\\n" +
+          "Build and artifacts available on [Blue Ocean](${env.RUN_DISPLAY_URL}) or [classic view](${env.BUILD_URL})"
+          echo comment_content
+          String filename = "Build_${currentBuild.fullDisplayName}_summary.txt"
+          writeFile(file: filename, text: comment_content)
+          archiveArtifacts(artifacts: filename, onlyIfSuccessful: true, fingerprint: true)
+          gerritReview(score:0, message: "Jenkins build for commit ${GIT_COMMIT_REV} (${MERGE_TYPE}) succeeded - see details on [Blue Ocean](${env.RUN_DISPLAY_URL}) or [classic view](${env.BUILD_URL})")
+        }
+      }
+      addBadge(icon: "success.gif", text: "Build Succeeded", id: "${GIT_COMMIT_REV}_${MERGE_TYPE}", link: env.BUILD_URL)
+    }
+    failure {
+      script {
+        if(MERGE_TYPE != "")
+        {
+          String comment_content = "Jenkins build for commit ${GIT_COMMIT_REV} (${MERGE_TYPE}) failed - see details on [Blue Ocean](${env.RUN_DISPLAY_URL}) or [classic view](${env.BUILD_URL})"
+          echo comment_content
+          gerritReview(score:-1, message: comment_content)
+          addErrorBadge(text: "Build Failed", id: "${GIT_COMMIT_REV}_${MERGE_TYPE}", link: env.BUILD_URL)
+        }
+      }
+    }
+    cleanup {
+      deleteDir()
+    }
+  }
+}
\ No newline at end of file
diff --git a/sam_cli.cfg b/sam_cli.cfg
new file mode 100755 (executable)
index 0000000..f88558a
--- /dev/null
@@ -0,0 +1,86 @@
+#!/usr/bin/env bash
+#
+# Copyright (C) 2019 The SAM Tool Authors. All rights reserved.
+#
+#               SAM (S/W Architecture Maturity)
+#
+# Samsung Research,
+# Samsung Electronics Co., Ltd.
+#
+# This software and its documentation are confidential and proprietary
+# information of Samsung Electronics Co., Ltd.  No part of the software and
+# documents may be copied, reproduced, transmitted, translated, or reduced to
+# any electronic medium or machine-readable form without the prior written
+# consent of Samsung Electronics.
+#
+# Samsung Electronics makes no representations with respect to the contents,
+# and assumes no responsibility for any errors that might appear in the
+# software and documents. This publication and the contents here of are subject
+# to change without notice.
+#
+
+################################
+# Project Name
+################################
+SAM_PRJ_NAME="Oobe"
+
+
+################################
+# Source Code
+################################
+BUILD_CMD="/usr/bin/dotnet build Oobe/Oobe.sln --source https://tizen.myget.org/F/dotnet/api/v3/index.json "
+CLEAN_CMD="/usr/bin/dotnet clean Oobe/Oobe.sln"
+SRC_PATH="$PWD/Oobe"
+SRC_LANG="cs"                             # Supported languages : c, cpp, auto_c_cpp, java, cs
+#SRC_SCOPE="config/src_scope.cfg"        # Scoping list
+#SRC_EXCLUDE="config/src_exclude.cfg"    # Excluding list
+
+
+################################
+# SCRA
+################################
+SCRA_SKIP=FALSE                             # Options : TRUE, FALSE
+SCRA_RAW_DATA_PATH=".scap/workspace/scra"
+SCRA_ROOT_TO_CUT=$SRC_PATH
+#SCRA_USE_PARAM=TRUE
+
+
+################################
+# ART_BEAN (Convert SCRA data)
+################################
+ART_BEAN_SKIP=FALSE                         # Options : TRUE, FALSE
+
+
+################################
+# PMD CPD (Duplicated Code)
+################################
+PMD_SKIP=FALSE                              # Options : TRUE, FALSE
+PMD_RAW_DATA_PATH=".scap/workspace/pmd"
+PMD_USE_BUILT_PATH=FALSE                    # Options : TRUE, FALSE
+PMD_ROOT_TO_CUT=$SRC_PATH
+#PMD_EXCLUDE_LIST="config/src_exclude.cfg"  # Excluding list of PMD
+#PMD_RESULT_DETAIL_MODE=FALSE               # Options : TRUE, FALSE
+#PMD_HEAP_SIZE=2048m
+#PMD_ENCODING="utf-8"
+
+
+################################
+# Metrix++ (Preprocessor)
+###############################
+MPP_SKIP=FALSE
+MPP_RAW_DATA_PATH=".scap/workspace/metrixpp"
+MPP_ROOT_TO_CUT=$SRC_PATH
+#MPP_USE_BUILT_PATH=TRUE
+
+
+################################
+# Advanced Option
+################################
+#ADVANCED_SAM_OPTION="config/sam.cfg"
+#USE_EMBEDDED_LIB=TRUE
+#LMCD_INIT=FALSE
+
+SCAP_TOOL_PATH="hub/code-analysis-hub/bin/scap"
+SCAP=$SCAP_TOOL_PATH
+
+SEND_DATA_FLAG=FALSE
diff --git a/sonar_build.sh b/sonar_build.sh
new file mode 100755 (executable)
index 0000000..dc78406
--- /dev/null
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+set -e
+set -x
+
+PROJECT_NAME="TizenOobeIotCI"
+AUTH_TOKEN="9f6fef1c61b4d7ee402310e0eaa8debaea47dc5b"
+SONAR_URL="https://sonar.sprc.samsung.pl"
+
+if ! [ -z "$1" ] && [ "$1" = "-m" -o "$1" = "--tizen" ] ; then
+    PROJECT_NAME="${PROJECT_NAME}_tizen"
+fi
+
+dotnet-sonarscanner  begin /k:"$PROJECT_NAME" /d:sonar.host.url="$SONAR_URL" /d:sonar.login="$AUTH_TOKEN"
+dotnet clean Oobe/Oobe.sln
+set +e
+dotnet restore Oobe/Oobe.sln --source https://tizen.myget.org/F/dotnet/api/v3/index.json
+set -e
+dotnet build Oobe/Oobe.sln 
+dotnet-sonarscanner end /d:sonar.login="$AUTH_TOKEN"
\ No newline at end of file
diff --git a/svace_build.sh b/svace_build.sh
new file mode 100755 (executable)
index 0000000..f8f238d
--- /dev/null
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+set -e
+set -x
+
+USER="$1"
+PASS="$2"
+
+svace init
+dotnet clean Oobe/Oobe.sln
+set +e
+dotnet restore Oobe/Oobe.sln --source https://tizen.myget.org/F/dotnet/api/v3/index.json
+set -e
+svace build --enable-lang csharp dotnet build Oobe/Oobe.sln
+svace analyze --enable-lang csharp
+svace upload --host 106.120.130.104:12000 --module Tizen_2019_IoT_Service_and_UI_Sample  --user $USER --pass $PASS
\ No newline at end of file