Running sonar job on C++ project which is getting build with MSbuild

We have C++ project which is getting build via MSbuild, below is the command.

        MSBuild "LiveCaptioning.sln" /t:Build /p:Configuration=Release"

We are using the jenkins which is running on kubernetes using helm. Below is my Jenkinsfile

node {
  stage('SCM') {
    checkout scm
  }
  stage('Download Build Wrapper') {
    sh "mkdir -p .sonar"
    sh "curl -sSLo build-wrapper-linux-x86.zip https://sonar-travis.watsonmedia.ibm.com/static/cpp/build-wrapper-linux-x86.zip"
    sh "unzip -o build-wrapper-linux-x86.zip -d .sonar"
  }
  stage('Build') {
    sh ".sonar/build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir bw-output MSBuild "LiveCaptioning.sln" /t:Build /p:Configuration=Release"
  }
  stage('SonarQube Analysis') {
    def scannerHome = tool 'sonarScanner';
    withSonarQubeEnv() {
      sh "${scannerHome}/bin/sonar-scanner -Dsonar.cfamily.build-wrapper-output=bw-output"
    }
  }
}

I am getting error on the same

Running on default-p0b2w in /home/jenkins/workspace/t-gbs_sonarqube-scanning-changes
[Pipeline] {
[Pipeline] stage
[Pipeline] { (SCM)
[Pipeline] checkout
The recommended git tool is: NONE
using credential token-for-wlc-client-gbs-repo
Cloning the remote Git repository
Cloning with configured refspecs honoured and without tags
Cloning repository https://github.ibm.com/watsonmedia-wlc/wlc-client-gbs.git
 > git init /home/jenkins/workspace/t-gbs_sonarqube-scanning-changes # timeout=10
Fetching upstream changes from https://github.ibm.com/watsonmedia-wlc/wlc-client-gbs.git
 > git --version # timeout=10
 > git --version # 'git version 2.30.2'
using GIT_ASKPASS to set credentials token for wlc-client-gbs repo
 > git fetch --no-tags --force --progress -- https://github.ibm.com/watsonmedia-wlc/wlc-client-gbs.git +refs/heads/sonarqube-scanning-changes:refs/remotes/origin/sonarqube-scanning-changes +refs/heads/*:refs/remotes/origin/* # timeout=10
Avoid second fetch
Checking out Revision 7a4d1644dd7221dc4ec112a84e9a8d6bb9443567 (sonarqube-scanning-changes)
 > git config remote.origin.url https://github.ibm.com/watsonmedia-wlc/wlc-client-gbs.git # timeout=10
 > git config --add remote.origin.fetch +refs/heads/sonarqube-scanning-changes:refs/remotes/origin/sonarqube-scanning-changes # timeout=10
 > git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
 > git config core.sparsecheckout # timeout=10
 > git checkout -f 7a4d1644dd7221dc4ec112a84e9a8d6bb9443567 # timeout=10
Commit message: "updated changes"
 > git rev-list --no-walk 2cbdb178e89924fb24dbb36c131ea3e2c3526a7f # timeout=10
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Download Build Wrapper)
[Pipeline] sh
+ mkdir -p .sonar
[Pipeline] sh
+ curl -sSLo build-wrapper-linux-x86.zip https://sonar-travis.watsonmedia.ibm.com/static/cpp/build-wrapper-linux-x86.zip
[Pipeline] sh
+ unzip -o build-wrapper-linux-x86.zip -d .sonar
Archive:  build-wrapper-linux-x86.zip
   creating: .sonar/build-wrapper-linux-x86/
  inflating: .sonar/build-wrapper-linux-x86/libinterceptor-x86_64.so  
  inflating: .sonar/build-wrapper-linux-x86/libinterceptor-haswell.so  
  inflating: .sonar/build-wrapper-linux-x86/libinterceptor-i686.so  
  inflating: .sonar/build-wrapper-linux-x86/build-wrapper-linux-x86-64  
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Build)
[Pipeline] sh
+ .sonar/build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir bw-output MSBuild
build-wrapper: execvp: No such file or directory
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 1

GitHub has been notified of this commit’s build result

Finished: FAILURE

Hi,

What do you make of that?

 
Ann

Hello Ann,

Is it possible to build the C++ project via MSbuild on Jenkins installed on linux instance or kubernetes.
or
Do i need to run it on windos jenkins only.

Hi,

You can build however you want (assuming you’re using a supported compiler, which MSBuild is). The docs should help.

 
Ann

I am trying to build this code in windows jenkins and which has MSBuild plugin installed and setup in Global configuration tools in jenkins.
I am able to build the project using MSBuild in a separate job with MSBuild.
But when i am using using multibranch pipeline project for same repo its giving me below error.

powershell.exe : [SONARSOURCE BUILD-WRAPPER] failed to execute MSBuild.exe LiveCaptioning.sln /p:Configuration=Release: The system cannot find the file specified.
At C:\Jenkins\workspace\r-job_sonarqube-scanning-changes@tmp\durable-7e22bfe3\powershellWrapper.ps1:3 char:1
+ & powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -Comm ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: ([SONARSOURCE BU...file specified.:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

My jenkinsfile is below

node {
  
  stage('SCM') {
    checkout scm
    //git credentialsId: 'github-creds-for-wlcdevus-user', 
    //url: 'https://github.ibm.com/watsonmedia-wlc/wlc-client-gbs.git'
  }
  stage('Download Build Wrapper') {
    powershell '''
      $path = "$HOME/.sonar/build-wrapper-win-x86.zip"
      rm build-wrapper-win-x86 -Recurse -Force -ErrorAction SilentlyContinue
      rm $path -Force -ErrorAction SilentlyContinue
      $FolderName = "$HOME/.sonar"
      if (Test-Path $FolderName) {
         Write-Host "Folder Exists"    
         }
      else
      {
        New-Item $FolderName -ItemType Directory
        Write-Host "Folder Created successfully"
        }
      [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
      (New-Object System.Net.WebClient).DownloadFile("https://sonar-travis.watsonmedia.ibm.com/static/cpp/build-wrapper-win-x86.zip", $path)
      Add-Type -AssemblyName System.IO.Compression.FileSystem
      [System.IO.Compression.ZipFile]::ExtractToDirectory($path, "$HOME/.sonar")
    '''
  }
  stage('Build') {
    powershell '''
      $env:Path += ";$HOME/.sonar/build-wrapper-win-x86"
      build-wrapper-win-x86-64.exe --out-dir bw-output "/c/Program Files (x86)/MSBuild/12.0/Bin/MSBuild.exe" "LiveCaptioning.sln" /p:Configuration=Release
    '''
  }
  stage('SonarQube Analysis') {
    def scannerHome = tool 'SonarScanner';
    withSonarQubeEnv() {
      powershell "${scannerHome}/bin/sonar-scanner -Dsonar.cfamily.build-wrapper-output=bw-output"
    }
  }
}

Hi,

This looks like a path problem.

It’s been a very long time since I had to use Windows, but I would have expected the path to start with C:\ rather than /c/…?

It might be helpful to compare how you invoke MSBuild in that separate job versus how you invoke it here.

 
Ann

Hello Ann,

When i used the path as you have suggested its giving the below error.

Obtained Jenkinsfile from 7d3aa2078cc31601462af4a2e04b5a0d7869f8a7
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 31: unexpected char: '\' @ line 31, column 59.
   64.exe --out-dir bw-output "C:\Program F
                                 ^

1 error

	at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:309)
	at org.codehaus.groovy.control.ErrorCollector.addFatalError(ErrorCollector.java:149)
	at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:119)
	at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:131)
	at org.codehaus.groovy.control.SourceUnit.addError(SourceUnit.java:349)
	at org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST(AntlrParserPlugin.java:220)
	at org.codehaus.groovy.antlr.AntlrParserPlugin.parseCST(AntlrParserPlugin.java:191)
	at org.codehaus.groovy.control.SourceUnit.parse(SourceUnit.java:233)
	at org.codehaus.groovy.control.CompilationUnit$1.call(CompilationUnit.java:189)
	at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:966)
	at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:626)
	at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:602)
	at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:579)
	at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:323)
	at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:293)
	at groovy.lang.GroovyShell.parseClass(GroovyShell.java:677)
	at groovy.lang.GroovyShell.parse(GroovyShell.java:689)
	at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:142)
	at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:127)
	at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:571)
	at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:523)
	at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:334)
	at hudson.model.ResourceController.execute(ResourceController.java:101)
	at hudson.model.Executor.run(Executor.java:442)

GitHub has been notified of this commit’s build result

Finished: FAILURE

I am really confused now.

Hi,

So this is a Groovy error; it doesn’t like the syntax. You may need to escape the \ or convert to /s. Sorry, but this part is a bit out of my scope.

 
Ann

Hello Ann,

Now i am facing a new thing. My analysis is not going to SonarQube after the build is successful.

Push event to branch sonarqube-scanning-changes
10:10:15 Connecting to https://github.ibm.com/api/v3 using wlcdevus@us.ibm.com/****** (github-creds-for-wlcdevus-user)
Obtained Jenkinsfile from 7dd6e6172bedd461a670ee1b9712b292a77f2b48
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in C:\Jenkins\workspace\r-job_sonarqube-scanning-changes
[Pipeline] {
[Pipeline] stage
[Pipeline] { (SCM)
[Pipeline] checkout
The recommended git tool is: NONE
using credential github-creds-for-wlcdevus-user
 > git.exe rev-parse --resolve-git-dir C:\Jenkins\workspace\r-job_sonarqube-scanning-changes\.git # timeout=10
Fetching changes from the remote Git repository
 > git.exe config remote.origin.url https://github.ibm.com/watsonmedia-wlc/wlc-client-gbs.git # timeout=10
Fetching without tags
Fetching upstream changes from https://github.ibm.com/watsonmedia-wlc/wlc-client-gbs.git
 > git.exe --version # timeout=10
 > git --version # 'git version 2.29.2.windows.3'
using GIT_ASKPASS to set credentials github-creds-for-wlcdevus-user
 > git.exe fetch --no-tags --force --progress -- https://github.ibm.com/watsonmedia-wlc/wlc-client-gbs.git +refs/heads/sonarqube-scanning-changes:refs/remotes/origin/sonarqube-scanning-changes +refs/heads/*:refs/remotes/origin/* # timeout=10
Checking out Revision 7dd6e6172bedd461a670ee1b9712b292a77f2b48 (sonarqube-scanning-changes)
 > git.exe config core.sparsecheckout # timeout=10
 > git.exe checkout -f 7dd6e6172bedd461a670ee1b9712b292a77f2b48 # timeout=10
Commit message: "updated"
 > git.exe rev-list --no-walk 3ad7c5d9fe10703b86dcececfecd7c79e1472cdd # timeout=10
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Download Build Wrapper)
[Pipeline] powershell
Folder Exists
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Build)
[Pipeline] powershell
Microsoft (R) Build Engine version 12.0.40629.0
[Microsoft .NET Framework, version 4.0.30319.42000]
Copyright (C) Microsoft Corporation. All rights reserved.

Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
Build started 2/23/2023 10:10:21 AM.
Project "C:\Jenkins\workspace\client-gbs-sonar-job_master\LiveCaptioning.sln" on node 1 (default targets).
ValidateSolutionConfiguration:
  Building solution configuration "Release|x64".
Project "C:\Jenkins\workspace\client-gbs-sonar-job_master\LiveCaptioning.sln" (1) is building "C:\Jenkins\workspace\client-gbs-sonar-job_master\LiveCaptioning.vcxproj" (2) on node 1 (default targets).
InitializeBuildStatus:
  Creating "C:\Jenkins\workspace\client-gbs-sonar-job_master\\build\LiveCaptioning\x64\Release\LiveCaptioning.tlog\unsuccessfulbuild" because "AlwaysCreate" was specified.
ClCompile:
  All outputs are up-to-date.
ResourceCompile:
  All outputs are up-to-date.
Link:
  All outputs are up-to-date.
  LiveCaptioning.vcxproj -> C:\Jenkins\workspace\client-gbs-sonar-job_master\\target\Max\x64\Release\LiveCaptioning.exe
PostBuildEvent:
  xcopy /D /R /Y C:\Jenkins\workspace\client-gbs-sonar-job_master\install\runtime\x64\* C:\Jenkins\workspace\client-gbs-sonar-job_master\target\Max\x64\Release\
  
  :VCEnd
  0 File(s) copied
FinalizeBuildStatus:
  Deleting file "C:\Jenkins\workspace\client-gbs-sonar-job_master\\build\LiveCaptioning\x64\Release\LiveCaptioning.tlog\unsuccessfulbuild".
  Touching "C:\Jenkins\workspace\client-gbs-sonar-job_master\\build\LiveCaptioning\x64\Release\LiveCaptioning.tlog\LiveCaptioning.lastbuildstate".
Done Building Project "C:\Jenkins\workspace\client-gbs-sonar-job_master\LiveCaptioning.vcxproj" (default targets).
Done Building Project "C:\Jenkins\workspace\client-gbs-sonar-job_master\LiveCaptioning.sln" (default targets).

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:01.00
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (SonarQube Analysis)
[Pipeline] tool
[Pipeline] withSonarQubeEnv
Injecting SonarQube environment variables using the configuration: SonarQubeServer
[Pipeline] {
[Pipeline] powershell
[Pipeline] }
WARN: Unable to locate 'report-task.txt' in the workspace. Did the SonarScanner succeed?
[Pipeline] // withSonarQubeEnv
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline

GitHub has been notified of this commit’s build result

Finished: SUCCESS

Hi,

A new thing deserves a new thread.

 
:smiley:
Ann

Shall i raise a new thread or you would be able to help me on this.