Create and use an analysis wrapper script

Starting in Klocwork 2025.4, you can create a wrapper script that generates portable environment bootstrap files, allowing analysis to run without any local pre-installed tools. Using the wrapper prepares your environment for analysis without manual setup, ideal for zero-install onboarding in ephemeral or containerized environments.

When executed, the wrapper script:

  • Validates your authentication credentials and checks for required tools

  • Downloads missing build tools from the tool store if they're not already present

  • Sets key environment variables such as:

    • PATH: Updated to include the latest kwanalysis build tools.

    • KW_PROJECT_NAME: The name of the project being analyzed.

    • KW_BUILDTOOLS_LOCATION: The directory where the latest kwanalysis build tools are located.

    • Default validation URL: Used for connecting to the Validate server during analysis.

Note that the wrapper script downloads its authentication tools from the tool store when it starts. Later, whenever it runs an analysis, it once again retrieves the required tools from the tool store. For more information on setting up the tool store, see Use the analysis tool store.

Create a wrapper script

To create a wrapper script, use kwanalysis wrapper:

kwanalysis wrapper --project <project-name>

The following files will be created:

  • kwanalysisw.sh

  • kwanalysisw.cmd

  • kwanalysisw.ps1

  • Bootstrap JAR: .kwanalysis/kwanalysisbootstrap.jar

  • properties file(s): .kwanalysis/kwanalysis.properties (default)

If you wish to generate multiple properties file for multiple projects, run:

kwanalysis wrapper --project <project_name> --properties <insert_name_of_properties_file> --properties-only

Run the wrapper script

Invoke the wrapper script with this command:

  • Linux: source kwanalysisw.sh

  • Windows PowerShell: . .\kwanalysisw.ps1

  • Windows command line: kwanalysisw.cmd --apply

Notes:

  • Sourcing is required to persist environment variables. On Linux or PowerShell, you must source the script (for example, source kwanalysis.sh or . .\kwanalysissw.ps1) so that environment variables remain active after the script finishes.

  • When using CMD, the --apply option sets environment variables for one session only. They will be lost when the shell closes.

  • Scripts automatically resolve missing tool versions. If the required version isn't found locally, the script will download or resolve it from the configured tool store.

  • The script support multiple authentication methods:

    • User name/password: Works both interactively and through the script

    • Application token: Recommended for CI pipelines because it's non-interactive and fully scriptable

    • Provided auth token: Also supported for script-based workflows

    • Modern authentication: Interactive only; ideal for developer desktops. If modern authentication is required, the wrapper will launch the authentication flow automatically.

Run backward-compatible analysis with wrapper scripts

This example demonstrates how to run an end-to-end backward-compatible analysis using wrapper scripts.

Step 1: One-time setup

  1. Lock the project (optional):

    kwadmin analysis-tool-version --tool-version 25.2 --tool-location /opt/klocwork/25.2/buildtools MyProject
  2. Generate wrapper script and check it in:

    kwanalysis wrapper --project MyProject

    This creates:

    • kwanalysisw.sh (Linux)

    • kwanalysisw.ps1 (PowerShell)

    • Bootstrap JAR and properties files in .kwanalysis/

Step 2: Analysis

For buildproject workflow:

  1. Source the wrapper script:

    Linux:

    source kwanalysisw.sh --application-token myAppToken123

    PowerShell:

    . .\kwanalysisw.ps1 --application-token myAppToken123
  2. Create your build specification:

    kwinject -w -o kwinject.out bash build.sh
  3. Run analysis (with optional checker sync):

    kwanalysis buildproject [--sync-checkers] --project MyProject -f -o kw_tables kwinject.out
  4. Load results into Validate:

    kwadmin load MyProject kw_tables

For CI agent workflow:

  1. Source the wrapper script:

    Linux:

    source kwanalysisw.sh --application-token myAppToken123

    PowerShell:

    . .\kwanalysisw.ps1 --application-token myAppToken123
  2. Create your build specification:

    kwinject -w -o kwinject.out bash build.sh
  3. Sync custom checkers for CI agent (optional):

    kwanalysis deploy sync --tool-location /opt/klocwork/25.2/buildtools
  4. Run CI agent analysis and create CI builds:

    kwanalysis ciagent --project MyProject --ci-build build_456
kwanalysis ciagent can create CI builds for projects locked to version 2022.4 and later. CI builds were introduced in 2023.1, so this feature supports backward compatibility.