🐛 fix(ci): handle missing sonar project key gracefully
- set default empty value for PROJECT_KEY variable - add fallback to read sonar-project.properties if secret is not provided - exit with error if PROJECT_KEY is still unset after checks
This commit is contained in:
parent
608b6b87cd
commit
02972a04d4
1 changed files with 8 additions and 2 deletions
|
|
@ -35,7 +35,14 @@ jobs:
|
|||
SONAR_PROJECT_KEY: ${{ secrets.SONAR_PROJECT_KEY }}
|
||||
run: |
|
||||
HOST_URL=${SONAR_HOST_URL:?SONAR_HOST_URL secret not set}
|
||||
PROJECT_KEY=${SONAR_PROJECT_KEY:?SONAR_PROJECT_KEY secret not set}
|
||||
PROJECT_KEY=${SONAR_PROJECT_KEY:-}
|
||||
if [ -z "$PROJECT_KEY" ] && [ -f sonar-project.properties ]; then
|
||||
PROJECT_KEY=$(grep -E '^sonar.projectKey=' sonar-project.properties | cut -d= -f2 | tr -d '\r')
|
||||
fi
|
||||
if [ -z "$PROJECT_KEY" ]; then
|
||||
echo "SONAR_PROJECT_KEY secret not set and no sonar-project.properties entry found" >&2
|
||||
exit 1
|
||||
fi
|
||||
docker run --rm \
|
||||
-e SONAR_HOST_URL="$HOST_URL" \
|
||||
-e SONAR_TOKEN="$SONAR_TOKEN" \
|
||||
|
|
@ -44,7 +51,6 @@ jobs:
|
|||
sonarsource/sonar-scanner-cli \
|
||||
sonar-scanner \
|
||||
-Dsonar.host.url="$HOST_URL" \
|
||||
-Dsonar.token="$SONAR_TOKEN" \
|
||||
-Dsonar.projectKey="$PROJECT_KEY" \
|
||||
-Dsonar.sources=. \
|
||||
-Dsonar.scm.provider=none \
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue