0
I have a Sonarqube deployment running on Tanzu Kubernetes. For this Sonarqube deployment I have setup a Gitlab-CI pipeline to run a sonar-scan on a .Net 6 API.
When I execute the GitlabCI pipeline I am getting an error :
$ cd /root/.dotnet/tools
$ ./dotnet-sonarscanner begin /k:"gl" /d:sonar.login="$SONAR_TOKEN" /d:"sonar.host.url=$SONAR_HOST_URL"
SonarScanner for MSBuild 5.13
Using the .NET Core version of the Scanner for MSBuild
Pre-processing started.
Preparing working directories...
12:06:38.194 Updating build integration targets...
12:06:38.428 Downloading from http://XX.X.XX.XX:9000/api/server/version failed. Http status code is Forbidden.
12:06:38.431 An error occured while querying the server version! Please check if the server is running and if the address is correct.
12:06:38.434 Pre-processing failed. Exit code: 1
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: command terminated with exit code 1
The GitlabCI pipeline is as below:
before_script:
- 'dotnet restore --packages $NUGET_PACKAGES_DIRECTORY'
build_job:
tags:
- orion
only:
- sonarqube
stage: build
script:
- dotnet build --configuration Release --no-restore
publish_job:
tags:
- orion
only:
- sonarqube
stage: publish
artifacts:
name: "$CI_COMMIT_SHA"
paths:
- ./$PUBLISH_DIR
script:
- dotnet publish ./src --configuration Release --output $(pwd)/$PUBLISH_DIR
analyze_job:
tags:
- orion
only:
- sonarqube
stage: analyze
image:
name: golide/net6-sonar:0.1.1
variables:
# Defines the location of the analysis task cache
SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"
GIT_DEPTH: 0
cache:
key: "${CI_JOB_NAME}"
paths:
- .sonar/cache
script:
- "cd /root/.dotnet/tools"
- "./dotnet-sonarscanner begin /k:\"gl\" /d:sonar.login=\"$SONAR_TOKEN\" /d:\"sonar.host.url=$SONAR_HOST_URL\" "
- "dotnet build"
- "./dotnet-sonarscanner end /d:sonar.login=\"$SONAR_TOKEN\""
allow_failure: true
I am using a custom .Net 6 image (golide/net6-sonar:0.1.1) with sonar tooling as follows :
FROM mcr.microsoft.com/dotnet/sdk:6.0
RUN dotnet tool install --global dotnet-sonarscanner
RUN echo $PATH
RUN export ENV PATH="$PATH:/root/.dotnet/tools"
RUN echo $PATH
The Sonarqube instance is already accessible from the rest of the internet (exposed via Kubernetes LoadBalancer service) and it is on the same network as the GitlabCI server.
What I have done:
- Configured SONAR_TOKEN in the GitLab CI pipeline project
- Configured SONAR_HOST_URL in the GitLab CI pipeline project
- Configured sonar-project.properties in my project as below :
sonar.projectKey=my_oasys
sonar.projectName=oasys
sonar.projectVersion=1.0
# Comma-separated paths to directories containing the source code (required)
sonar.sources=.
# Language and plugin settings
sonar.language=cs
sonar.cs.analyzer.projectOutPathsEnabled=true
# Encoding of the source files
sonar.sourceEncoding=UTF-8
# Analysis exclusions (optional)
sonar.exclusions=**/bin/**/*, **/obj/**/*
# Test exclusions (optional)
sonar.test.exclusions=**/*Test.cs
# SonarQube server URL (adjust as per your setup)
sonar.host.url=http://xx.x.xx.xx:9000
VERSIONS Sonarqube version - Version 7.1.0.11001 Postgres version - 10.4 (Debian 10.4-2.pgdg90+1)
What am I missing ?