Setting up Sonarcloud with Jenkins in C/C++

Hello, I am a beginner in the use of SonarCloud and I encountered a problem when trying to get it to analyze my program with Jenkins.

Some info :
ALM : Github
CI : Jenkins
Language : C

Scanner command (used in my Jenkinsfile) :
sonar-scanner
-D’sonar.organization=<my_org_name>’
-D’sonar.projectKey=<my_project_name>’
-D’sonar.sources=.’
-D’sonar.host.url=https://sonarcloud.io’
-D’sonar.cfamily.build-wrapper-output=bw-output’
-D’sonar.login=${sonar_login}’

My question is about the use of Build Wrapper with Jenkins, since my program is completely written in C. When looking at the documentation, it seems to me that the build wrapper can only be launched locally (with the command build-wrapper-win-x86-64.exe --out-dir bw-output ).
I tried doing this and then adding the bw-output folder into my GitHub repo but I noticed that the build-wrapper-dump.json file created contains only absolute paths to my local files.
The problem is that Jenkins is supposed to perform the sonar-scanner command after pushing my program to the Github repo. This means that sonar-scanner can’t understand what are those paths, right ?

I wanted to ask if there is a way to use Build-Wrapper online with Jenkins, or if it has to be done locally ? More generally, could you guide me on setting things up so that SonarCloud can analyze my C program whenever a push is done on Github ?

I hope I’m being clear enough. If not, don’t hesitate to ask for more information.
Thanks in advance for your answers !

Hi @HLEURE30,

you can build and analyze on jenkins, you should modify the build on jenkins to be wrapped by `build-wrapper-win-x86-64.exe --out-dir bw-output.

Hello,

Thank you for your anwser ! Sadly I tried this already and the log tells me
build-wrapper-win-x86-64.exe: not found

I got this output by adding the build-wrapper command to the Jenkinsfile like this :
stage (‘Build’) {
steps {
sh “”"
build-wrapper-win-x86-64.exe --out-dir bw-output make clean test
“”"
}
}

Was this what you meant, or should I have added this command somewhere in some Jenkins build options in the parameters?

Edit : I forgot to mention, I am using Jenkins hosted on a cloud by my company, not directly installed on my computer. Could this be the issue ?

Hi @HLEURE30,

build-wrapper-win-x86-64.exe must be in the path, you should add its download before the invocation.

Thanks you for your answer. Sorry to bother you again but I’m not sure I quite understand exactly what you mean.

I tried adding the build-wrapper-win-x86-64.exe into the source of my GitHub repo, hoping this could work and that the Jenkinsfile would recognize the command. It seems like it wasn’t the solution since it didn’t change anything.

When you say I should add the download before the invocation, do you mean I should add a sh command to download build-wrapper ? Or should I use withEnv() command with the PATH leading to build-wrapper ? If so, how can I know the exact PATH to this command ? I am using a Jenkins on which I don’t have access to everything, so for example I can’t access Manage Jenkins => Global Properties => Environment variables, is it a problem ?

Thank you

Hi @HLEURE30,

as you can read in the documentation you can add the download of the build-wrapper before its execution, something like:

curl -L -O {SonarQube URL}/static/cpp/build-wrapper-win-x86.zip
unzip build-wrapper-win-x86.zip
build-wrapper-win-x86\build-wrapper-win-x86-64.exe --out-dir  bw-output make clean test