A common question from users that run Kiuwan in a Continuous Integration scenario is :
How can i control (or be notified of) the results of the execution of Kiuwan Local Analyzer?
And furthermore.. How could those results influence my build process?
Kiuwan provides several mechanisms that depend on your specific Continuous Integration scenario. Let’s look at it in detail.
Continuous Integration through Jenkins
If you are using Jenkins, you are probably using our Kiuwan Plugin for Jenkins (https://www.kiuwan.com/docs/display/K5/Jenkins+plugin).
In case you are not using it, you will be running the Local Analyzer from the command-line, so in the next section we will show you how to control the execution. Nevertheless, please consider using it because it will enormously facilitate your configuration and flexibility.
When using Kiuwan Plugin for Jenkins, Local Analyzer can be run in three different modes, and results (return codes) can be bound to Jenkins’ build.
In Baseline mode, you can execute a baseline analysis, check its results, and change the status of your build if the selected measure does not meet the selected thresholds.
By using this mode, you can mark the build as UNSTABLE or FAILURE depending on thresholds defined over Global Indicator, Risk Index or Effort to Target.
For example, you might define a build status to be FAILURE if the Global Indicator is under 50, UNSTABLE if between 50 and 70, and as a SUCCESS only if it is higher than 70.
In this way, you can seamlessly integrate Kiuwan in the build process, allowing it to be as strict as you want.
In Delivery mode, you can base Jenkins’ build status depending on the Audit you have defined in Kiuwan.
As an example, you could mark the build as FAILURE if the current analysis contains any new high priority defects (compared to any previous analysis). This mode will give you an accurate and very precise control over Kiuwan’s analysis results.
In Expert mode, you can fully control all the available behavior settings of Kiuwan.
Moreover, you will get a fine-grain control on Jenkins’ build status depending on Kiuwan’s return codes (see next section in this post to know more about return codes)
For that, Kiuwan Plugin for Jenkins provides a configuration page to mark Jenkins’s build status (SUCCESS, UNSTABLE, FAILURE, NOT_BUILT, ABORTED, etc.) depending on Kiuwan’s execution results.
Command-Line execution of Kiuwan Local Analyzer
If you are executing Kiuwan Local Analyzer from a shell script (or from any other automation script), you are using the Command-Line Interface (CLI mode).
As you probably know, CLI mode allows a full control of the Local Analyzer’s behavior. Please see https://www.kiuwan.com/docs/display/K5/Code+analysis+using+the+downloaded+agent for a full description of settings.
Beyond to fully control the analyzer’s behavior, you can also get full information over the analysis results.
Basically, Kiuwan Local Analyzer command scripts (agent.cmd and agent.sh) return 0 after a successful execution. Return codes (other than 0) will inform you of specific reasons for errors .
In Windows you can check return code in %ERRORLEVEL%, in Unix you can check it in $?
You can find the full reference of Kiuwan Local Analyzer return codes, reason and suggested actions at https://www.kiuwan.com/docs/display/K5/Local+Analyzer+Return+Codes