install git plugin in jenkins
- we start the tomcat instance for jenkins by executing the tomcat jenkins - start.cmd script
- open a browser and navigate to: http://localhost:8075/jenkins/
- click in the menu on Manage Jenkins
- click on Manage Plugins
- select the Available tab
- search for SonarQube plugin
- install this plugin and restart jenkins
integrate sonarqube and jenkins
- we start the tomcat instance for jenkins by executing the tomcat jenkins - start.cmd script
- open a browser and navigate to: http://localhost:8075/jenkins/
- click in the menu on Manage Jenkins
- click on the Configure link
- navigate to the SonarQube servers section
- click on the Add SonarQube
- Name: SonarQube 5.4.
- Server URL: http://localhost:9000/
- Server Version: 5.3 or higher
create continuous integration job
- we start the tomcat instance for jenkins by executing the tomcat jenkins - start.cmd script
- open a browser and navigate to: http://localhost:8075/jenkins/
- click in the sidemenu on New Job
- for this exercise, we are using the account status webservice
- call this item: wsaccountstatus_sonar
- select the first radiobutton create a freestyle project
- in the Source Code Management section select the Git radiobutton
- enter the url: https://bitbucket.org/johantuitel/easywebservices.git
- select the credentials you have made for your bitbucket account
- in my case it was j.tuitel@developers.nl/*(bitbucket account)
- after that we need to set the correct branch in the field Branches to build
- enter: develop
- add a build step and select Invoke Top-level Maven
- target: clean install
- POM: AccountStatusWebservice\pom.xml
- navigate to the Actions after build
- select the SonarQube analysis with Maven
- branch: develop
- JDK: j.d.k. 1.8
- Maven Version: Apache-Maven-3.3.9
- click on Save and we are done
- build the project and when its succesfull you will see this(IMG)
- click on the SonarQube icon to start SonarQube
- when we navigate to the Coverage section and we don't see any results. In the next paragraph
adding testcoverage with the JaCoCo maven plugin
- we need to add dependency in the pom.xml
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.3</version>
</dependency>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.6.201602180812</version>
</dependency>
- next we need to add a profile to build the specific sonar reports
<profile>
<id>sonar</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.6.201602180812</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
- we need to configure the job so the sonar profile is executed
- navigate to http://localhost:8075/jenkins/job/ws_account_status_sonar/configure
- go the the Invoke top-level Maven targets section
- adjust the Goal clean install > clean install -Psonar
- build the project
- navigate to sonar by clicking on the icon
- when you click on the Coverage tab, you won't see anything. This is because there is not any test present, so make a unittest and you wil see some coverage