Installation (Ubuntu)
Pre-requisite
- Database (We are using the default h2 db)
- Java 8
- Both must be pre-installed on your machine
...
Table of Contents |
---|
For quality analysis we are using SonarQube at SonarQube.com
CI analysis
Job Configuration
Sonarqube analysis must be done with JDK 8!
SonarScanner is deprecated and analysis should be done with maven
Preview (pull request)
For pull request we don't want to upload the result to sonar but we wan't to check quality gates&etc so use preview mode
Code Block | ||
---|---|---|
| ||
### As root (or sudo infront of all commands)###
# Create sonar user and set password
adduser --no-create-home --disabled-login --disabled-password sonar
passwd sonar
# Get the latest nexus oss version
wget https://sonarsource.bintray.com/Distribution/sonarqube/sonarqube-6.2.zip -O /tmp/install/
# Unzip and point to latest (ex 6.2)
mkdir -p /opt/sonar
unzip zxvf /tmp/install/sonarqube-6.2.zip -C /opt/sonar/
ln -sfn /opt/sonar/sonarqube-6.2 /opt/sonar/current
|
Systemd service
Code Block | ||
---|---|---|
| ||
# Create sonar systemd script cat > /etc/systemd/system/sonar.service << 'EOF' [Unit] Description=Sonarqube After=network.target network-online.target Wants=network-online.target [Service] ExecStart=/opt/sonar/current/bin/linux-x86-64/sonar.sh start ExecStop=/opt/sonar/current/bin/linux-x86-64/sonar.sh stop ExecReload=/opt/sonar/current/bin/linux-x86-64/sonar.sh restart PIDFile=/opt/sonar/current/bin/linux-x86-64/./SonarQube.pid Type=forking User=sonar [Install] WantedBy=multi-user.target EOF # Activate the service with the following commands: sudo systemctl daemon-reload sudo systemctl enable sonar.service sudo systemctl start sonar.service # After starting the service for any Linux-based operating systems, verify that the service started successfully. tail -f /opt/sonar/current/logs/sonar.log # The tail command verifies that the service has been started successfully. # If successful, you should see a message notifying you that it is listening for HTTP. # IMPORTANT: Be sure to assign the appropriate permissions to the user running the sonar service. -Dsonar.analysis.mode=preview |
Run with JDK8+
If the project is build with JDK8 or newer versions:use "Invoke top-level Maven targets" in a post build step:
Code Block | ||||
---|---|---|---|---|
| ||||
Maven Version=Maven3
Goals=$SONAR_MAVEN_GOAL -Dsonar.host.url=$SONAR_HOST_URL -Dsonar.login=$SONAR_AUTH_TOKEN $SONAR_EXTRA_PROPS |
Run with JDK7 or older
If the project is build with JDK7 or older versions: use "Execute shell" in a post build step (SonarScanner is deprecated)
Code Block | ||||
---|---|---|---|---|
| ||||
JAVA_HOME=/var/lib/jenkins/tools/hudson.model.JDK/JDK8
PATH=$JAVA_HOME/bin:$PATH
/var/lib/jenkins/tools/hudson.tasks.Maven_MavenInstallation/Maven3/bin/mvn $SONAR_MAVEN_GOAL -Dsonar.host.url=$SONAR_HOST_URL -Dsonar.login=$SONAR_AUTH_TOKEN $SONAR_EXTRA_PROPS
|
Global Tool Configuration
SonarQube Scanner is deprecated and should not be used.
Global System Configuration
Jenkins is configured to use SonarQube.com (uses token GLESYS_JENKINS in sonarqube.com for uvms github user)
(extra options: -Dsonar.organization=uvms-github -Dsonar.exclusions=**/apidocs/** -Dsonar.dynamicAnalysis=reuseReports)
IDE analysis
For IntelliJ/Eclipse use SonarLint
Analysis
For the current src file right click and "Analyze File with SonarLint"
Ex in IntelliJ:
Configure
Add Sonar server under the settings for Sonarlint
Use https://sonarqube.com (no need for authentication as we only do preview analysis)
Ex in IntelliJ: