forked from rwspeight/DotnetSonarScanner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scan.sh
executable file
·60 lines (49 loc) · 1.26 KB
/
scan.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
set -o errexit
set -o nounset
# Parameter defaults
projectPathDefault="."
sonarUrlDefault="https://sonarcloud.io"
# Syntax help
syntax=$(cat<<END
::
:: Purpose
:: Analyzes a C# project using coverlet
:: and sonar-scanner and sends results to
:: SonarQube server (i.e. SonarCloud)
::
:: Syntax
:: $(basename $0) \\
:: [Sonar project key] \\
:: [Sonar organization] \\
:: [Sonar auth token] \\
:: [Unit test DLL path] \\
:: [C# project path (default:$projectPathDefault)] \\
:: [SonarQube server URL (default:$sonarUrlDefault)]
::
END
)
# Required params
sonarProjectKey=${1:?"$syntax"}
sonarOrg=${2:?"$syntax"}
sonarToken=${3:?"$syntax"}
unitTestDllPath=${4:?"$syntax"}
# Optional params
projectPath=${5:-"$projectPathDefault"}
sonarUrl=${6:-"$sonarUrlDefault"}
# Variables
coveragePath="/tmp/opencover.xml"
dotnet-sonarscanner begin \
-d:sonar.host.url=$sonarUrl \
-key:$sonarProjectKey \
-o:$sonarOrg \
-d:sonar.login=$sonarToken \
-d:sonar.cs.opencover.reportsPaths=$coveragePath
dotnet build -c Release $projectPath
coverlet \
$unitTestDllPath \
--target "dotnet" \
--targetargs "test $unitTestDllPath --no-build" \
-f opencover -o $coveragePath
dotnet-sonarscanner end \
-d:sonar.login=$sonarToken