Must-share information (formatted with Markdown):
-
which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
Sonarqube 9.5.0.56709 -
what are you trying to achieve
I want to be able to scan a bitbucketed gradle+java project file system for the presence of specfic filenames, which will indicate whether the java project has a legacy configuration (a local construct we want to eliminate). We want people to stop using that construct, so to detect and dashboard their progress with upgrading their projects we want to detect those files as a “smell” and report it in Sonar’s dashboard. -
what have you tried so far to achieve this
I looked for a Rule that I could make a custom Template off, but found nothing I thought I could use. I have a simple linux “find” that discovers the bad files.
I have a gradle task that will execute that linux find set up as per SonarScanner for Gradle | SonarCloud Docs
It finds the bad files and fails the “gradle sonarqube” build locally as expected when files are present (via the Task usingexit 1
if it finds the files), but it does not feed any details back to sonarqube’s localhost:9000 dashboard that I can find.
If I run a sonarqube build without it my build shows up in the localhost dashboard. If I “exit 0” rather than “exit 1” then it shows the ERROR in the gradle build console and completes the sonarqube run, but still the specfic test result is not to be found in the localhost dashboard.
How do I get that “find bad file” Gradle Task result returned to the sonarqube Task and sent back as a “smell” to the Sonarqube dashboard?
Or, what other approach should I change to, to detect some nuisance file name pattern in java projects in bitbucket and flag them as having a smell?
NB: these are a particular local config file, not java files, so “find ./src/main -type f -iname bannedfilename*.yml”.
task detectTabooLocalFiles(type: Exec) {
executable "sh"
commandLine 'bash', '-c', """
if [ 1 -le `find ./src/main -type f -iname bannedfilename*.yml | wc -l` ] ;
then
echo 'ERROR: Found taboo local bannedfilename*.yml';
find ./src/main -type f -iname bannedfilename*.yml
echo 'To be fully compliant, move the content of these to the approved location.'
exit 0;
fi
"""
}
project.tasks ["sonarqube"].dependsOn "detectTabooLocalFiles"
Thanks in advance
Rob