SonarCloud is a code quality and security tool that is free to open-source projects.
SonarCloud does not work with Subversion code repositories, so if your project uses SVN, you will need to use an Apache GitHub mirror of your SVN project. Create a Jira ticket asking Infra to set up this mirror for your project. See the PDFBox Jenkins job and this related INFRA Jira ticket as an example of an SVN-based project using Sonarcloud and GitHub.
Project members who will be responsible for running SonarCloud need to create SonarCloud accounts. Log in to sonarcloud.io with your ASF GitHub credentials.
If you do not see any Apache project in SonarCloud, make sure you have configured a Public access to your ASF organization membership in GitHub. See how to make public or hide your organizational membership.
File an INFRA Jira ticket to have a new project created at sonarcloud.io for your ASF project. On the ticket:
(Project keys must contain at least one non-digit character. Allowed characters are: 'a' through 'z', 'A' through 'Z', '-' (dash), '_' (underscore), '.' (dot), ':' (colon) and digits '0' to '9'. This value is case-sensitive.)
To configure SonarCloud analysis, you need:
Here is an example of how to run the SonarCloud analysis in a Jenkins file:
stage('Code Quality') { steps { echo 'Checking Code Quality on SonarCloud' // Main parameters def sonarcloudParams="-Dsonar.host.url=https://sonarcloud.io -Dsonar.organization=apache -Dsonar.projectKey=apache_project_key_provided_by_infra" if ( env.BRANCH_NAME.startsWith("PR-") ) { // this is a pull request sonarcloudParams="${sonarcloudParams} -Dsonar.pullrequest.branch=${CHANGE_BRANCH} -Dsonar.pullrequest.base=${CHANGE_TARGET} -Dsonar.pullrequest.key=${CHANGE_ID}" } else { // this is just a branch sonarcloudParams="${sonarcloudParams} -Dsonar.branch.name=${BRANCH_NAME}" } // Then run the analysis // 'my-sonarcloud-token' needs to be defined for this job and contains the user token withCredentials([string(credentialsId: 'my-sonarcloud-token', variable: 'SONAR_TOKEN')]) { sh 'mvn clean verify sonar:sonar ${sonarcloudParams} -Dsonar.login=${SONAR_TOKEN}' } } }
Note that sonarcloud.io now supports a monorepo configuration. See docs here and file an INFRA ticket should you wish to utliise this setup in your project(s).