Hello.
I’m new to SonarCloud and yesterday I spent several hours trying to set up SonarCloud with GitLab CI/CD for a Platformio project.
I took inspiration from your official guide and replace cmake with Platformio.
The .gitlab-ci.yml is the following
image: python:3.11
cache:
paths:
- ~/.cache/pip
- ~/.platformio/.cache
variables:
PIO_LIB_FOLDER: lib
SONAR_SERVER_URL: "https://sonarcloud.io"
SONAR_SCANNER_VERSION: 5.0.1.3006 # Find the latest version in the "Linux" link on this page:
# https://docs.sonarcloud.io/advanced-setup/ci-based-analysis/sonarscanner-cli/
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:
- "pip install -U platformio"
script:
# prepare the build tree
- mkdir build
# run the build inside the build wrapper
- build-wrapper/build-wrapper-linux-x86-64 --out-dir "${BUILD_WRAPPER_OUT_DIR}" platformio ci -e "ArduinoMaster" --build-dir="./build" --keep-build-dir --project-conf=platformio.ini ./src/
#- "pio run -e ArduinoSlaveRelay"
artifacts:
paths:
- ${BUILD_WRAPPER_OUT_DIR}/build-wrapper-dump.json
#- src/sonar_scanner_example
cache:
policy: pull-push
key: "${CI_COMMIT_SHORT_SHA}"
paths:
- build-wrapper/
- sonar-scanner/
- "${BUILD_WRAPPER_OUT_DIR}"
sonarcloud-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.build-wrapper-output="${BUILD_WRAPPER_OUT_DIR}"
The sonar-project.properties:
sonar.projectKey=paolino625_dcc-command-station
sonar.organization=paolino625
# This is the name and version displayed in the SonarCloud UI.
#sonar.projectName=DCC Command Station
#sonar.projectVersion=1.0
# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
sonar.sources=src
sonar.sourceEncoding=UTF-8
# sonar.cfamily.build-wrapper-output=bw-output
I had a look at the build-wrapper-dump.json and it SEEMS ok to me.
I’m attaching it here.
build-wrapper-dump.json (7.0 MB)
While executing the job I get the following error at the sonarcloud-check stage.
ERROR: Error during SonarScanner execution
java.lang.IllegalStateException: The "build-wrapper-dump.json" file was found but 0 C/C++/Objective-C files were analyzed. Please make sure that:
* you are using the latest version of the build-wrapper and the CFamily analyzer
* you are correctly invoking the scanner with correct configuration
* your compiler is supported
* you are wrapping your build correctly
* you are wrapping a full/clean build
* you are providing the path to the correct build-wrapper output directory
* you are building and analyzing the same source checkout, absolute paths must be identical in build and analysis steps
I’m attaching here the full logs of SonarScanner with -X flag.
LogSonarScanner.txt (1.9 MB)
It must be an easy detail I missed but I cannot find out which one is.
Any suggestions?
Thank you in advance!