Uploaded image for project: 'SonarQube'
  1. SonarQube
  2. SONAR-15033

Explain how to analyse C/C++/Objective C with Jenkins

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 9.0
    • Component/s: Web
    • Labels:
      None
    • Edition:
      Community
    • Production Notes:
      None

      Description

      Important: we do not tell the user to set up any specific build plugins, as there are too many possibilities. We assume the user has configured their Jenkins runners correctly to be able to build C projects. We will show an info box explaining all necessary build tools are assumed to be installed on the runner.

      Setting instruction should be provided to add projectkey in sonar-project.properties file

      We will provide an OS selector.

      For Windows the Jenkins file should contain:

       

       

      node {
        stage('SCM') {
          checkout scm
        }
        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
            mkdir $HOME/.sonar
            [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
            (New-Object System.Net.WebClient).DownloadFile("[REPLACE WITH URL IN FRONTEND]/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 --out-dir bw-output <your clean build command>
          '''
        }
        stage('SonarQube Analysis') {
          def scannerHome = tool 'SonarScanner';
          withSonarQubeEnv() {
            powershell "${scannerHome}/bin/sonar-scanner -Dsonar.cfamily.build-wrapper-output=bw-output"
          }
        }
      }
      

      For Linux it should contain:

       

       

      node {
        stage('SCM') {
          checkout scm
        }
        stage('Download Build Wrapper') {
          sh "mkdir -p .sonar"
          sh "curl -sSLo build-wrapper-linux-x86.zip [REPLACE WITH URL IN FRONTEND]/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 <your clean build command>"
        }
        stage('SonarQube Analysis') {
          def scannerHome = tool 'SonarScanner';
          withSonarQubeEnv() {
            sh "${scannerHome}/bin/sonar-scanner -Dsonar.cfamily.build-wrapper-output=bw-output"
          }
        }
      }
      

      and for OSX:

       

      node {
        stage('SCM') {
          checkout scm
        }
        stage('Download Build Wrapper') {
          sh '''
            mkdir -p .sonar
            curl -sSLo build-wrapper-macosx-x86.zip [REPLACE WITH URL IN FRONTEND]/static/cpp/build-wrapper-macosx-x86.zip
            unzip -o build-wrapper-macosx-x86.zip -d .sonar
          '''
        }
        stage('Build') {
          sh '''
            .sonar/build-wrapper-macosx-x86/build-wrapper-macosx-x86 --out-dir bw-output <your clean build command>
          '''
        }
        stage('SonarQube Analysis') {
          def scannerHome = tool 'SonarScanner';
          withSonarQubeEnv() {
            sh "${scannerHome}/bin/sonar-scanner -Dsonar.cfamily.build-wrapper-output=bw-output"
          }
        }
      }
      

       

       

      Towards the end of the tutorial, add the following sentence (standard for all new C/C++/Obj C tutorials):

      If you have trouble using the build wrapper, you can check out using a compilation database. Read more about it [here|/documentation/analysis/languages/cfamily/].
      You can speed up your analysis by enabling multi-threading and caching. Read more about it [here|/documentation/analysis/languages/cfamily/].

       

       

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              mathieu.suen Mathieu Suen
              Reporter:
              mathieu.suen Mathieu Suen
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Due:
                Created:
                Updated:
                Resolved: