-
Notifications
You must be signed in to change notification settings - Fork 4
/
.gitlab-ci.yml
71 lines (66 loc) · 2.85 KB
/
.gitlab-ci.yml
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
61
62
63
64
65
66
67
68
69
70
71
image: gcc
variables:
SONAR_SERVER_URL: https://next.sonarqube.com/sonarqube # Replace with your SonarQube server URL
SONAR_SCANNER_VERSION: 5.0.1.3006 # Find the latest version in the "Linux" link on this page:
# https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed
SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar" # Defines the location of the analysis task cache
GIT_DEPTH: "0" # Tells git to fetch all the branches of the project, required by the analysis task
# note that SONAR_TOKEN is transmitted to the environment through Gitlab CI
get-sonar-binaries:
# this job download and unpacks the build-wrapper and the sonar-scanner
# in this example it is done for every build.
# This can be optimized by caching the files or better, by including them, in the build docker image.
stage: .pre
script:
# Download sonar-scanner
- curl -sSLo sonar-scanner.zip "https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${SONAR_SCANNER_VERSION}-linux.zip"
- unzip -o sonar-scanner.zip
- mv sonar-scanner-${SONAR_SCANNER_VERSION}-linux sonar-scanner
# Download build-wrapper
- curl -sSLo build-wrapper.zip "${SONAR_SERVER_URL}/static/cpp/build-wrapper-linux-x86.zip"
- unzip -o build-wrapper.zip
- mv build-wrapper-linux-x86 build-wrapper
cache:
policy: push
key: "${CI_COMMIT_SHORT_SHA}"
paths:
- build-wrapper/ # to share the build-wrapper between jobs
- sonar-scanner/ # to share the sonar-scanner between jobs
build:
stage: build
# install the necessary build tools when needed
before_script:
- apt update && apt -y install cmake
script:
# prepare the build tree
- mkdir build
- cmake -S . -B build
# run the build inside the build wrapper
- build-wrapper/build-wrapper-linux-x86-64 --out-dir "${BUILD_WRAPPER_OUT_DIR}" cmake --build build/ --config Release
artifacts:
paths:
- build/sonar_scanner_example
cache:
policy: pull-push
key: "${CI_COMMIT_SHORT_SHA}"
paths:
- build-wrapper/
- sonar-scanner/
- "${BUILD_WRAPPER_OUT_DIR}"
sonarqube-check:
stage: .post
cache:
policy: pull
key: "${CI_COMMIT_SHORT_SHA}"
paths:
- sonar-scanner/
- "${BUILD_WRAPPER_OUT_DIR}"
script:
- sonar-scanner/bin/sonar-scanner --define sonar.host.url="${SONAR_SERVER_URL}" --define sonar.cfamily.compile-commands="${BUILD_WRAPPER_OUT_DIR}/compile_commands.json"
# if you are using using sonarqube 10.5 or earlier, replace sonar.cfamily.compile-commands with sonar.cfamily.build-wrapper-output="${BUILD_WRAPPER_OUT_DIR}"
# as build-wrapper does not generate a compile_commands.json file before sonarqube 10.6
only:
- merge_requests
- main
- develop