How Can We Help?
Search for answers or browse our knowledge base.
Update Entities with SonarQube Quailty
Overview
With SyncNow Quality Gate information can be publish to work systems. SyncNow DevOps Gate works with SonarQube webhookd and publishes quality code scan information to entities in target system.
The following article elaborates the process of Setting Sonarqube webhook and with Jenkins as an example for publishing information with custom parameters to target systems
Usage Examples
Publish Quality of code to work systems features , epics mentioned in code
- Update Sonarqube status to entities mentioned in comments
- Add Sonarqube status and link in comments of entities mentioned in comments
- Link Soarqube report url to entities mentioned in comments
Step By Step Instructions
- Create a DevOps Gate process for SonarQube Scan Status with configuration like on images below
- Set map for SonarQube virtual entity which represent SonarQube data to an entity in target system, map can be different for every entity type
- Map the fields from SonarQube information to entity fields
- Go to the Configuration page and press the Create | Update an Entity button. Copy the WebHook URL.
Create an entity in target system the URL should be
{SyncNowBackend}/api/v1.0/app/DevOpsGate/Enrich/{DevOpsGateProcessID}?action=create
To Update and entity the URL should be
{SyncNowBackend}/api/v1.0/app/DevOpsGate/Enrich/{DevOpsGateProcessID}?action=update
To add a comment with sonarqube link The URL Should be in the following format
{SyncNowBackend}/api/v1.0/app/DevOpsGate/Enrich/{DevOpsGateProcessID}?action=comment |
To link SonarQube URL to an entity
{SyncNowBackend}/api/v1.0/app/DevOpsGate/LinkIt/{DevOpsGateProcessID} |
- Go to the SonarQube system. Navigate to Administration -> Configuration -> WebHooks page
- In a dialog that appeared paste a WebHook URL (step 2 in this tutorial);
- Press the Create button
- Security : It is highly commended to add a secret for communicating with SyncNow
7. Set Security parameters in SyncNow System connector UI
- Add sonarqube parameters from Jenkins script, parameters can be custom defined, custom parameters should correspond to field mapping in DevOpsgate process entity mapping
@NonCPS
def getCommentsString() {
def list = []
def changeLogSets = currentBuild.changeSets
for (int i = 0; i < changeLogSets.size(); i++) {
def entries = changeLogSets[i].items
for (int j = 0; j < entries.length; j++) {
def entry = entries[j]
if (entry.msg != null) {
list.add("""${entry.commitId} on ${new Date(entry.timestamp)}: ${entry.msg.replaceAll("[\n\r]", " ")}""")
}
}
}
return list.join(',')
}
pipeline {
agent any
stages {
stage("SonarQube Analysis") {
steps {
script{
def commits = getCommentsString()
def scannerHome = tool 'main_sonar_scanner';
withSonarQubeEnv('sonarmain') {
sh """${scannerHome}/bin/sonar-scanner -Dsonar.analysis.param.Param1='Sonar Quality Tests for Build ${JOB_NAME}' -Dsonar.analysis.param.Param4='${env.VERSION}.${env.BUILD_ID}' -Dsonar.analysis.targetDetail.Project=<TargetSystemProjectKey>
-Dsonar.analysis.targetDetail.CommitComments='${commits}' -Dsonar.analysis.targetDetail.EventRelativeURL='/job/${JOB_NAME}/${env.BUILD_ID}' -Dsonar.analysis.targetDetail.CommentLinkTitle='SonarQube Report' """
}
}
}
}
}
- Verify that the script is running and data is published to SyncNow