To load the plugin we need to restart the container.
docker
exec
-
u
0
ci
wget
--
no
-
check
-
certificate
https
:
/
/
www
.salvis
.com
/
blog
/
?
ddownload
=
6680
-
O
/
opt
/
tvdcc
.zip
docker
exec
-
u
0
ci
unzip
/
opt
/
tvdcc
.zip
-
d
/
opt
docker
exec
-
u
0
ci
bash
-
c
"mv /opt/tvdcc-* /opt/tvdcc"
docker
exec
-
u
0
ci
rm
/
opt
/
tvdcc
.zip
Why do we need to install this component in the “ci” container and not in the “sonar” container? Well, the SonarQube scanner is executed in the “ci” container and gets the code analyzer from the SonarQube server. This increases the scalability of the code analyzers since just the analysis reports need to be sent to the SonarQube server. However, the PL/SQL Cop SonarQube plugin is basically a wrapper to the command line utility. This means that every Jenkins agent needs to have PL/SQL Cop installed in the location configured on the SonarQube server.
In an environment with multiple servers and multiple Jenkins agents the PL/SQL Cop installations need to be identical on every agent.
Open “http://localhost:9010” in your web browser.
Press “Log in” in the upper right corner and login into SonarQube with the username “admin” and password “admin”.
Click on “Settings” and the Category “Trivadis PL/SQL Cop” and change the “Path to PL/SQL Cop command line tvdcc executable” to “/opt/tvdcc/tvdcc.sh”.
Press “Save Trivadis PL/SQL Cop Settings” and your done.
Open “http://localhost:9020” in your web browser.
Jenkins generated during the container creation a password for the user admin. To get this password execute in a terminal window the following:
docker
exec
ci
cat
/
var
/
jenkins_home
/
secrets
/
initialAdminPassword
Copy the output into the clipboard and paste it into the “Administrator password” field in the browser window and press “Continue”.
Press on “Install Suggested Plugins”
Wait until all plugins are installed.
Enter the requested fields and press “Save and Finish”. And on the next page Click on “Start Using Jenkins”
Click on “Mange Jenkins”.
Click on “Manage Plugins”.
Select “SonarQube Scanner for Jenkins” in the “Available” tab. Use the filter to find the entry. Press “Install without restart”.
Click on “Go back to top page” when the plugins have been installed successfully.
Click on “Manage Jenkins” (again) and then on “Global Tool Configuration”.
Within the Global Tool Configuration click on “Add SonarQube Scanner”, add a name for the scanner and press “Save”.
Click on “Configure System”.
Scroll down to the “SonarQube servers” section and click on “Add SonarQube”.
Enter “SonarQube 5.1.2” for name, enter “http://sonar:9000” for “Server URL”, select “5.1 or lower” in “Server version” and enter “jdbc:h2:tcp://sonar/sonar” for “Database URL”. Click on “Save” to complete the Jenkins configuration.
Please note, that we are accessing the host sonar via the internal network Docker Compose has set up for us. Therefore we have to use the default port 9000 and not port 9010 which we are using from outside, e.g. to access SonarQube in the web browser.
Click on “create new jobs”.
Enter “plscope-utils” and click on “Freestyle project”
Click on the “Source Code Management” tab, select “Git”, enter “https://github.com/PhilippSalvisberg/plscope-utils” for “Repository URL”, add “Sparse Checkout paths” in “Additional Behaviours”, enter “database/utils” for “Paths” and click on “Apply”.
Click on “Build Triggers” tab, select “Poll SCM”. Enter “H/15 * * * *” for “Schedule” and press “Apply”. This will look for changes in the Git repository every 15 minutes and starts a build if a change is detected.
Click on “Build” tab and Scroll down to the Build section and add a “Execute SonarQube Scanner” build step.
Copy the following lines into the “Analysis properties”.
sonar
.
projectKey
=
plscope
-
utils
:
main
sonar
.
projectName
=
plscope
-
utils
sonar
.
projectVersion
=
0.5.0
sonar
.
sources
=
database
sonar
.
language
=
plsqlcop
and click on “Save”.
Wait until the initial build is started or click on “Build Now” and then on “#1” (the first build job in the Build History).
Click on “Console Output”.
The analysis result has been stored successfully in SonarQube and can now be queried via http://localhost:9010 .
Please note, that the link to SonarQube provided in the console output is not working, since it is referring a port of the internal Docker Compose network which is not accessible to your browser. However, it is possible to configure the external IP address and port for SonarQube in Jenkins and than this link will work.
Setting up an continuous code quality inspection environment for a PL/SQL project with Docker is quite simple. The audioless video documents the complete process.
Granted, for production use you need to use a different database as SonarQube backbone, define some roles and manage users and probably integrate an Active Directory. That should not be too difficult, at least not technijcally.
But the most challenging part will be to agree on some rules, adapt your development process and really improve your code quality over time. So, let’s get started.