At this time SQL Enlight does not offer a plugin for Jenkins CI, but the integration is possible using the SQL Enlight command line interface.
In this tutorial we will see how to configure SQL Enlight to run as a CI build step, use the command line tool to generate HTML and JUnit reports and publish the reports inside Jenkins.
Installing SQL Enlight on Build Machines
Before configuring report generation, SQL Enlight 1.9.9.917 or later must be installed on the machines used as a Jenkins build agent. There were some report enhancements, which were introduced in this version and used in this tutorial.
SQL Enlight license have to be activated for each of the windows user accounts with which the build agents run.
This command can be used activate the license for some other user account:
CD /D "C:\Program Files (x86)\Ubitsoft\SQL Enlight"
runas.exe /profile /env /user:username@domain "%comspec% /k enlight.exe license /action:activate /key:XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-XXX"
In case the account running the build agents is a system account, the PsExec tool from the sysinternals suite can be used.
To activate the license directly:
PsExec.exe -i -u "nt authority\network service" "C:\Program Files (x86)\Ubitsoft\SQL Enlight\enlight.exe" license /action:activate /key:XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-XXX"
Or to run the license wizard:
PsExec.exe -i -u "nt authority\network service" "C:\Program Files (x86)\Ubitsoft\SQL Enlight\enlight.exe" license /action:wizard"
Generate code analysis report with SQL Enlight command line tool
Add a build step to execute Enlight tool from the command line and generate analysis report XML file.
See here for a full list of the supported analyze
command arguments.
Fail the build in case of rule violations
Use the /exitCodeOnViolaton
parameter to provide a custom exit code, which to be returned when the code analysis finds rule violations. The exit code will set the ERRORLEVEL
environment variable after completion of the batch command and if the code is the same as the ERRORLEVEL
code configured in Jenkins, the build will be set unstable.
Generate JUnit and HTML reports
In another batch command step, run the command line tool with the report
command twice – once to generate a HTML report from the XML analysis report and again for JUnit report generation from the XML analysis report
Publish JUnit reports to Test results
Use the JUnit plugin to publish the prepared in the previous step JUint report to the Test Results.
Viewing the Test Results
In the test results, all analysis rule violations can be examined.
Description and details of each rule violation can also be seen.
Publish the report using the HTML report
In order to publish reports for viewing within Jenkins the HTML Publisher plugin must be installed.
There is one problem with viewing the generated HTML report inside Jenkins – it is that the default Content Security Policy (CSP) configuration is very restrictive and blocks JavaScript, inline CSS and CSS from external websites. The policy have to be adjusted to allow the embedded SQL Enlight Analysis report to be viewed correctly.
To be able to test the settings, temporarily the Content Security Policy can be configured using the Jenkins Script Console and by running the following command:
System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", "sandbox allow-scripts; default-src 'self'; style-src 'self' 'unsafe-inline';script-src 'self' 'unsafe-inline';")
This way of configuration is temporarily and will be resented next time Jenkins is restarted. To make the configuration permanent, this header setting have to be made during Jenkins startup.
The most common ways to provide arguments at Jenkins startup can be seen in the article: Adjusting the Jenkins Content Security Policy.
Viewing the HTML report
After the Content Security Policy is adjusted, the HTML report can be viewed inside Jenkins.
If you would like to have a plugin integration with Jenkins, you can vote for it on SQL Enlight-s User Voice site.