C family project
Using YAML or the Azure Classic interface to create the Azure build pipeline for C family projects.
Before you begin, read Azure Pipelines integration overview.
Once you have created your project in SonarQube Server and set up feature integration for your project, you can add the SonarQube Server analysis to your Azure build pipeline.
In your build pipeline, insert the following steps in the order they appear here. These steps can be interweaved with other steps of your build as long as the following order is followed. All steps have to be executed on the same agent.
To create your Azure build pipeline, you can use either YAML or the Azure Classic interface.
Step 1: Make the Build Wrapper available on the build agent.
Download and unzip the Build Wrapper on the build agent, as explained below, according to your build agent type. See also the CFamily Prerequisites page. The archive to download and unzip depends on the host’s platform.
Step 2: Add a Prepare Analysis Configuration task
If you want to use a specific scanner version, see Using various features.
Step 3: Add a Command Line task to run your build
For the analysis to happen, your build has to be run through a command line so that it can be wrapped-up by the build-wrapper.
To do so, run Build wrapper executable and pass in as the arguments:
The output directory configured in the previous task.
The command that runs a clean build of your project (not an incremental build): see the command examples below.
PowerShell commands on a Windows host with an MSBuild build build-wrapper-win-x86/build-wrapper-win-x86-64.exe --out-dir <outputDirectory> MSBuild.exe /t:Rebuild
Bash commands on a Linux host with a make build build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir <outputDirectory> make clean all
Bash commands on a Linux ARM64 host with a make build build-wrapper-linux-aarch64/build-wrapper-linux-aarch64 --out-dir <outputDirectory> make clean all
Example of bash commands on a macos host with a xcodebuild build build-wrapper-macosx-x86/build-wrapper-macos-x86 --out-dir <outputDirectory> xcodebuild -project myproject.xcodeproj -configuration Release clean build
Step 4: Add a Run code analysis task
Add a SonarQube’s Run code analysis task to run the code analysis and make the results available to SonarQube. Consider running this task right after step 3’s Command line task as the build environment should not be significantly altered before running the analysis.
Step 5: Add a Publish quality gate result task.
Add a new SonarQube’s Publish quality gate Result task.
YAML file example
If you use YAML to create your Azure build pipeline, see the example below and also our YAML pipeline templates. For information about the SonarQube task inputs, see SonarQube tasks for Azure Pipelines.
trigger:
- master # or the name of your main branch
- feature/*
steps:
- checkout: self
# disable shallow fetch
fetchDepth: 0
# Make Build Wrapper available
- task: Bash@3
displayName: Download Build Wrapper
inputs:
targetType: inline
script: |
curl '<YourSonarQubeURL>/static/cpp/build-wrapper-linux-x86.zip' --output build-wrapper.zip
unzip build-wrapper.zip
# Prepare Analysis Configuration task
- task: SonarQubePrepare@7
inputs:
SonarQube: '<YourSonarqubeServiceEndpoint>'
scannerMode: 'cli'
configMode: 'manual'
cliProjectKey: '<YourProjectKey>'
extraProperties: |
"sonar.cfamily.compile-commands=bw_output/compile_commands.json"
# Command Line task to run your build.
- task: Bash@3
displayName: Bash Script
inputs:
targetType: inline
script: |
./build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir bw_output <Your build command>
# Run Code Analysis task
- task: SonarQubeAnalyze@7
# Publish Quality Gate Result task
- task: SonarQubePublish@7
inputs:
pollingTimeoutSec: '300'
Related pages
Using various features when adding the analysis to your pipeline
Last updated
Was this helpful?