I am trying to put together a CI environment for a .NET application using the following stack (just the relevant ones):
- Debian + mono
- Docker
- Gitlab CI
- Gitlab-multi-runner (as a docker container)
- Sonarqube + Postgre
I've used docker-compose to create the container for sonarqube and postgre, both are running and working. I am sadly stuck with executing sonarqube analysis for my build executed by the gitlab runner and all examples I found were using Maven. I've tried to use sonar-scanner as well, no luck so far.
Here are the contents of my gitlab-ci.yml:
image: mono:latest
cache:
paths:
- ./src/T_GitLabCi/packages/
stages:
- build
.shared: &restriction
only:
- master
tags:
- docker
build:
<<: *restriction
stage: build
script:
- nuget restore ./src/T_GitLabCi
- MONO_IOMAP=case xbuild /t:Build /p:Configuration="Release" /p:Platform="Any CPU" ./src/T_GitLabCi/T_GitLabCi.sln
- mono ./tools/NUnitConsoleRunner/nunit3-console.exe ./src/T_GitLabCi/T_GitLabCi.sln --work=./src/T_GitLabCi/test --config=Release
- << EXECUTE SONAR ANALYSIS >>
I am definitely missing something here. Could somebody point me the right direction?
You need to install
sonar-scanner
first. You can find portage of sonar-scanner for almost any recent language, for example for npm you don't have to use directly the java executor:I only add to do this :
Then I needed to add this in my
package.json
This is my job in
.gitlab-ci.yml
:With this, I am able to start sonar analysis, but I am not able to use the quality gates after.
Hope this help.
I have projects written in PHP but that shouldn't matter. Here's what I did.
In this registry I have a "sonar-scanner" image built from this
Dockerfile
(it's based on one of the images available on Docker hub):and here's the
files/sonar-scanner-run.sh
file:Now in my project in
.gitlab-ci.yml
I have something like this:That't pretty much all. The above example of
.gitlab-ci.yml
is simplified since I'm using diffrent builds for master and other branches (likewhen: manual
) and I use this plugin to get feedback in GitLab: https://gitlab.talanlabs.com/gabriel-allaigre/sonar-gitlab-pluginFeel free to ask if you have any questions. It took me some time to put this all together the way I want it :) Actually I'm still finetuning it.