Skip to main content

How to Speed Up Build Execution Times

Configure a build configuration in BuildNinja to drastically reduce build execution time and shorten developer feedback loops. This guide shows how to optimize builds by reusing cached dependencies and source checkouts, and by stopping execution early when failures occur. This configuration uses:

  • Smart Caching to reuse VCS checkouts and dependencies across builds
  • Execution Steps with Success Exit Codes to fail fast and avoid wasted compute time

Prerequisites

Before you begin, ensure that:

  • You have access to a BuildNinja project.
  • A BuildNinja agent is registered and online.
  • Your repository contains a buildable application (for example, Node.js, Java, or Gradle-based).
  • Dependency installation and test commands return proper exit codes (0 for success, non-zero for failure).

Step 1: Create a Build Configuration

  1. Navigate to Projects.

    how-to-build-ninja-project-overview

  2. Select the project where you want to configure the build.

    how-to-speedup-how-to-project

  3. Click New Build Configuration.

    how-to-speedup-how-to-project-new-build-configuration-button

  4. Enter the following details:

    • Build Configuration Name (for example, Optimized Build with Caching)
    • Description (optional)

    how-to-speedup-new-configuration-page

  5. Click Create.

    how-to-speedup-new-configuration-page-create-button

    For more information about creating and managing build configurations, see Configure and Edit BuildsBuilds in a CI/CD environment represent a defined set of execution steps that run automatically to build, test, package, or prepare an application for deployment..

Step 2: Configure VCS Settings

  1. Navigate to VCS Settings.

    how-to-speedup-vcs-settings-page

  2. Ensure Cache is enabled.

    how-to-speedup-vcs-settings-page-cache-button

  3. Click Add VCS.

    how-to-speedup-vcs-settings-page-add-vcs-button

  4. Enter the following details:

    • VCS Root Type: Git
    • VCS Name: A unique identifier
    • Repository URL: Git repository URL
    • Branch: main, develop, or your target branch
    • Checkout Directory: Optional, default is recommended
    • Authentication Mode: Select the required authentication method

    how-to-speedup-add-vcs-page

  5. Click Test Connection to verify access (optional).

    how-to-speedup-add-vcs-page-test-connection-button

  6. Click OK to add the VCS.

    how-to-speedup-add-vcs-page-ok-button

  7. Click Save.

    how-to-speedup-vcs-settings-page-save-button

    note

    When Cache is enabled, BuildNinja reuses unchanged VCS checkouts and dependencies between builds, eliminating repeated clone operations and reducing build startup time.

Step 3: Configure Execution Steps (Optimized and Fail-Fast)

Execution Steps define what runs, where it runs, and how failures are handled. To speed up build execution, steps are ordered to validate early and stop immediately on failure.

Step 3.1: Install Dependencies

Dependency installation is expensive. With Smart Caching, unchanged dependencies are reused. If installation fails, the build stops immediately instead of wasting time on later steps.

  1. Navigate to Execution Steps.

    how-to-speedup-execution-steps-page

  2. Click Add Execution Step.

    how-to-speedup-execution-steps-add-execution-step-button

  3. Enter the following details:

    • Select Runner: Command Line
    • Step Name: Install Dependencies
    • Commands:
      npm install
    • Success Exit Code: 0. This is the default value. The step is considered successful only if the command exits with code 0.
    • Execute Next Command: Stop on Failure. If this command fails, no further commands or steps are executed.

    how-to-speedup-add-execution-step-page

  4. Click OK to add the execution step.

    how-to-speedup-add-execution-step-ok-button

Step 3.2: Run Unit Tests

Tests are intentionally placed before the build step. If tests fail, the build step is never executed, saving time and compute resources.

  1. Click Add Execution Step.

    how-to-speedup-tests-execution-steps-add-execution-step-button

  2. Enter the following details:

    • Select Runner: Command Line
    • Step Name: Run Unit Tests
    • Commands:
      npm test
    • Success Exit Code: 0. Any non-zero exit code marks the step as failed.
    • Execute Next Command: Stop on Failure. Ensures the build fails immediately if tests fail.

    how-to-speedup-tests-add-execution-step-page

  3. Click OK to add the execution step.

    how-to-speedup-tests-add-execution-step-ok-button

Step 3.3: Build Application

The build step runs only if dependencies are installed successfully, and tests passed with the expected success exit code. This prevents slow builds from running on broken code.

  1. Click Add Execution Step.

    how-to-speedup-build-execution-steps-add-execution-step-button

  2. Enter the following details:

    • Select Runner: Command Line
    • Step Name: Build Application
    • Commands:
      npm run build
    • Success Exit Code: 0
    • Execute Next Command: Stop on Failure

    how-to-speedup-build-add-execution-step-page

  3. Click OK to add the execution step.

    how-to-speedup-build-add-execution-step-ok-button

  4. Click Save to save the Execution Steps.

    how-to-speedup-execution-step-save-button

Step 4: Run Build and Evaluate Performance

Your build configuration is now complete.

Running a build executes the defined steps, including fetching the source code, restoring cached dependencies, running validation steps, and building the application.

In BuildNinja, build configurations define what a build does and control how efficiently it runs, enabling faster feedback through caching and fail-fast execution.

Step 4.1: Run Build Manually

  • Click Run Build to start the build manually. Once triggered, the build enters the execution queue and starts automatically when a compatible agent becomes available.

    how-to-speedup-run-build-button

Step 4.2: Review Build Performance

After the build starts or completes, review the build results to observe:

  • Faster startup due to reused VCS checkouts and cached dependencies
  • Immediate build termination when a step fails (for example, dependency install or tests)
  • Reduced overall execution time for successful builds

how-to-speedup-build-log

To quantify improvements, compare the build duration with previous runs or non-optimized configurations.