Command Line Interface & Build servers

If you are using a build server or other system to automate your builds, you can include the verification scan as part of this process to automatically list the results, for example using cron. We are internally using the system this way using an Ubuntu-based custom build server.

Calling verify from the command line interface

The system ships with a ready-to-use command line entry point, Sparrow.Verification.VerifyCLI.Run. You do not need to write any custom code: point Unity’s -executeMethod at it and it will run the scan, write the results to a file, and set the process exit code so your build server can react to failures.

The full call looks like this. The only required part is the -executeMethod; all of the -verify… arguments are optional:

Unity -batchmode -quit -projectPath <path> -executeMethod Sparrow.Verification.VerifyCLI.Run
      [-verifyProfile <profile caption>]   (default: all profiles)
      [-verifyOutput <path.json>]           (default: verify-results.json)
      [-verifyJUnit <path.xml>]             (optional JUnit XML report)
      [-verifyFailOn <error|warning|info>]  (default: error)
  • -verifyProfile: run a single Verify Profile by its caption. If omitted, all profiles in the project are run (and if the project has no profiles, a full scan with the default checks is performed).
  • -verifyOutput: path of the JSON report to write. Each entry contains the profile, category, message, severity and object path. Defaults to verify-results.json.
  • -verifyJUnit: if provided, an additional JUnit-style XML report is written to this path, which most CI systems can display natively (one test suite per profile, one test case per check category).
  • -verifyFailOn: the minimum severity that counts as a failure. Defaults to error.

The process exit code tells you the outcome: 0 means no results at or above the fail threshold, 1 means the threshold was hit, and 2 signals an unexpected error. This makes it easy to fail a build automatically when problems are found.

This is the Linux call we use to run this on a headless build server. You can adjust it to your needs; a full documentation on how to do this is beyond the scope of this documentation and project:

xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' /opt/Unity/Editor/Unity -quit -batchmode -nographics -projectPath /myProjectPath/ -executeMethod Sparrow.Verification.VerifyCLI.Run -verifyOutput /builds/verify-results.json -verifyJUnit /builds/verify-results.xml -verifyFailOn error

If you would rather generate your own report format, you can also call the verification system directly from your own editor script. VerifySystem.Run() performs a scan and returns the list of VerifyResult objects, each of which exposes its category, description and severity:

using Sparrow.Verification;
using UnityEngine;
using System.IO;

public static class BuildServerFunctions
{
    // this function can be called from the command line via -executeMethod
    public static void PerformVerify()
    {
        var results = VerifySystem.Run(VerifyResult.CheckType.All);

        Debug.Log($"Verify found {results.Count} problems in project {Application.productName}.");

        using (var writer = new StreamWriter("./Builds/verifyReport.txt", true))
        {
            results.Sort((a, b) => a.category.CompareTo(b.category));
            foreach (VerifyResult result in results)
                writer.WriteLine($"[{result.severity}] {result.category}: {result.description}");
        }
    }
}

Integration into build servers

You can integrate your Verify scan into Travis CI or Circle CI by including the command line call in the CI system’s build script. In the respective configuration file (e.g., .travis.yml for Travis CI or config.yml for Circle CI), add a step that executes the VerifyCLI.Run call above. Ensure that the required environment with Unity and all dependencies is set up. This allows you to automatically run the scan with each build and evaluate the results accordingly – use the exit code to fail the build, or the JUnit XML report to surface the results in your CI dashboard.

Was this page helpful?