Index: build/unittest.sh =================================================================== diff -u -rabab3de160d3512446a5f7d19c20b8c015b642ae -r37ae4e443f7adbc7154a860694d50f3678fc0894 --- build/unittest.sh (.../unittest.sh) (revision abab3de160d3512446a5f7d19c20b8c015b642ae) +++ build/unittest.sh (.../unittest.sh) (revision 37ae4e443f7adbc7154a860694d50f3678fc0894) @@ -427,7 +427,7 @@ | tee $LOG_PATH/cmreport.log } - +# Function to run SonarQube function runSonarQube() { # shellcheck disable=SC2155 @@ -438,49 +438,67 @@ local sonarRunProject="UI-SonarRun" local inlineScriptForReport="sonarReportGeneration.sh" echo " ------------------------------ Running SonarQube test" - + # Make a folder for SonarQube operations mkdir "$sonarFolder" cd "$sonarFolder" || return + # Clone the application and checkout the branch that is being built git clone ssh://git@devapps.diality.us:7999/bl/setupscript.git ./setupscript/projectsetup.sh "${buildSpecs[$PROJECT_NAME_INDEX]}" "${buildSpecs[$PROJECT_CHECKOUT_INDEX]}" \ "${buildSpecs[$COMMON_CHECKOUT_INDEX]}" cd application || return + # Create a log file and inline shell script touch "$sonarLogs" touch "$inlineScriptForReport" + # The inline shell script is created here and is copied into the Sonar server and run the report. Set the script as + # executable chmod +x "$inlineScriptForReport" - + # Run the alarm mapping for the latest updates ./alarmMapping.sh - + # Run qmake to compile the application "/opt/Qt5.15.10/5.15.10/gcc_64"/bin/qmake - + # Run the sonar build wrapper and run the make command. Write the results to the log file and also display it on the portal /opt/build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir "$currentDir"/"$sonarFolder"/"$buildWrapperJson" \ make -j8 | tee -a "$sonarLogs" - + # Copy the created build wrapper json file into the application folder cp "$currentDir"/"$sonarFolder"/"$buildWrapperJson"/build-wrapper-dump.json "$(pwd)" - + # Run sonar command. The password is located in the /opt/ folder in the build server and for the password open that + # file and read the first line as the password /opt/sonar-scanner-4.8.0.2856-linux/bin/sonar-scanner -Dsonar.projectKey="$sonarRunProject" -Dsonar.sources=. \ -Dsonar.cfamily.build-wrapper-output=. \ -Dsonar.cfamily.threads=4 -Dsonar.host.url=http://192.168.10.41:9000 \ -Dsonar.login=admin -Dsonar.password="$(head -n 1 /opt/sonarQubeServerPass)" | tee -a "$sonarLogs" - + # Copy the sonar logs into the remote build directory cp -r "$sonarLogs" "$REPORT_DIR" + # shellcheck disable=SC2129 + # NOTE: when creating the inline script '' was used to prevent expanding the commands. (e.g. $(pwd) will remain $(pwd) + # and not expanded prior to copying into the sonar server) + # Create and inline shell script. This script is run in the sonar server + # cd into the sonar reports + # Get the current date + # Run the sonar report generation command and set the output to be written to the error log + # Find all the .docx files in the report folder that has run date (e.g. 01-11-2024) + # echo the name of the file back to the build server so it can be remote copied echo 'cd /home/dnavaei/Downloads/SonarQube_Reports' >> "$inlineScriptForReport" + # shellcheck disable=SC2016 echo 'latestRunDate=$(date +%Y-%m-%d)' >> "$inlineScriptForReport" + # shellcheck disable=SC2016 echo 'runReport=$(java -jar sonar-cnes-report-4.2.0.jar -p $sonarRunProject -t \ aa04ef5851c9cd5bcaaa305e7173714a2739b3f0 2>error.log)' >> "$inlineScriptForReport" + # shellcheck disable=SC2016 echo 'docxFile=$(find $(pwd) -name "*.docx" | grep "$latestRunDate")' >> "$inlineScriptForReport" + # shellcheck disable=SC2016 echo 'echo $docxFile' >> "$inlineScriptForReport" - + # Copy the created script into the Sonar server. Use sshpass -f to get the password from the file sshpass -f /opt/sonarQubeServerPass scp "$(pwd)/$inlineScriptForReport" dnavaei@192.168.10.41:~/ - + # ssh into the sonar server and run the copied shell script reportAddress=$(sshpass -f /opt/sonarQubeServerPass ssh -t dnavaei@192.168.10.41 ./"$inlineScriptForReport") - echo "Here is the file I got: $reportAddress" - + echo "Sonar created file: $reportAddress" + # Copy the created SonarQube file from the sonar server to the remote directory sshpass -f /opt/sonarQubeServerPass scp dnavaei@192.168.10.41:"$reportAddress" "$REPORT_DIR" - + # Done with the sonar operations, go back to the upper address cd "$currentDir" || return }