-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
- id: sonarqube-precommit-hook | ||
name: SonarQube Pre-commit Hook | ||
description: Run SonarQube scan before committing. | ||
entry: ./run-sonarqube-scan.sh | ||
language: script | ||
files: \.java$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/sh | ||
|
||
# Use environment variables if available, otherwise fallback to defaults | ||
SONAR_PROJECT_KEY=${SONAR_PROJECT_KEY:-"default-project-key"} | ||
SONAR_ORGANIZATION=${SONAR_ORGANIZATION:-"default-organization"} | ||
SONAR_HOST_URL=${SONAR_HOST_URL:-"https://sonarcloud.io"} | ||
SONAR_LOGIN=${SONAR_LOGIN:-"<your-sonarcloud-token>"} | ||
|
||
# Run SonarQube scan | ||
echo "Running SonarQube scan before commit..." | ||
|
||
mvn clean verify sonar:sonar \ | ||
-Dsonar.projectKey=$SONAR_PROJECT_KEY \ | ||
-Dsonar.organization=$SONAR_ORGANIZATION \ | ||
-Dsonar.host.url=$SONAR_HOST_URL \ | ||
-Dsonar.login=$SONAR_LOGIN | ||
|
||
# Exit with non-zero status if scan fails | ||
if [ $? -ne 0 ]; then | ||
echo "SonarQube scan failed. Aborting commit." | ||
exit 1 | ||
else | ||
echo "SonarQube scan passed. Proceeding with commit." | ||
fi |