Skip to content

How to Automate API Testing with Bruno CLI in Jenkins

Jenkins is a powerful open-source automation server that enables continuous integration and continuous delivery (CI/CD) for software development workflows. It provides a robust platform for automating build, test, and deployment processes across multiple environments and platforms.

Bruno CLI integrates seamlessly with Jenkins pipelines to automate API testing workflows. This guide will walk you through setting up automated test execution using Jenkins CI.

βœ… Prerequisites

  • A running Jenkins instance (local or remote).
  • Bruno CLI installed.
  • The NodeJS Plugin installed in your Jenkins environment.
  • A Git repository containing your Bruno collections and a Jenkinsfile.

πŸ§‘β€πŸ’» Local Development Setup

If you're using macOS, you can use the following setup to configure Jenkins in your system.

Step 1: Install Jenkins via Homebrew

Run the following command on the terminal to install Jenkins.

brew install jenkins-lts

The jenkins-lts package installs the Long Term Support version of Jenkins, which is recommended for stability.

Step 2: Start the Jenkins Service

After installation, start the Jenkins service using Homebrew's services command:

brew services start jenkins-lts

Step 3: Access Jenkins in Your Browser

Jenkins typically runs on port 8080. Open your web browser and navigate to:

http://localhost:8080

You will be greeted with the "Unlock Jenkins" screen.

Step 4: Unlock Jenkins and Install Plugins

  1. Retrieve the initial admin password: The Jenkins console will display the path to the initial admin password. You can also find it by running:

    cat /Users/Shared/Jenkins/Home/secrets/initialAdminPassword

    Copy this password.

  2. Paste the password: In the browser, paste the copied password into the "Administrator password" field and click Continue.

  3. Install suggested plugins: On the next screen, choose Install suggested plugins. This will install a set of essential plugins required for most Jenkins functionalities.

  4. Create First Admin User: After the plugins are installed, you'll be prompted to create your first admin user. Fill in the details and click Save and Finish.

  5. Jenkins is Ready: Click Start using Jenkins to access your Jenkins Dashboard.

Screenshot 2025-06-26 at 12.04.40 PM

πŸ€– Automate API Testing with Jenkins

Now, let's start with automating the API testing workflow with Jenkins and Bruno CLI. This section will guide you for structuring your Bruno collection, the sample Jenkinsfile, and the initial setup you need to configure.

Step 1: Organize Your Bruno Collections

Ensure your Bruno collections and environment files are properly organized within your Git repository. A typical structure looks like this:

your-api-project/
β”œβ”€β”€ Jenkinsfile
β”œβ”€β”€ collections/
β”‚   β”œβ”€β”€ authentication/
β”‚   β”‚   β”œβ”€β”€ login.bru
β”‚   β”‚   └── logout.bru
β”œβ”€β”€ environments/
β”‚   β”œβ”€β”€ development.bru
β”‚   β”œβ”€β”€ ci.bru
β”‚   └── production.bru
└── bruno.json

Step 2: Configure Node.js in Jenkins

Before running Bruno CLI, you need to ensure Jenkins can access a Node.js runtime environment.

  1. Install the NodeJS Plugin:
    • Navigate to Manage Jenkins > Plugins.
    • Select the Available plugins tab, search for NodeJS, and install it.

Screenshot 2025-06-26 at 11.42.20 AM

  1. Configure a Node.js Installation:
    • Go to Manage Jenkins > Tools (under System Configuration).
    • Scroll down to the NodeJS installations section and Click Add NodeJS.
    • Provide a descriptive Name (e.g., Node.js 18). This exact name will be used in your Jenkinsfile.
    • Check Install automaticallyand select your desired Node.js version (e.g., NodeJS 18.20.8).

    • Crucially, ensure the checkbox "Provide Node & npm folder to PATH" is checked. This ensures node and npm commands are available to your pipeline.
    • Click Save.

Screenshot 2025-06-26 at 11.45.54 AM

Step 3: Create Your Jenkinsfile

Create a file named Jenkinsfile in the root of your Git repository. This file defines the steps of your CI pipeline.


pipeline {
    agent any // Run the pipeline on any available Jenkins agent
    stages {
        stage('Checkout Code') {
            steps {
                // Clones the repository to the Jenkins workspace
                checkout scm
            }
        }
        stage('Setup Node.js & Install Bruno CLI') {
            steps {
                // Makes the Node.js installation (configured in Jenkins Tools) available
                tool 'Node.js 18' // Use the exact name configured in Jenkins Global Tool Configuration
                echo 'Verifying Node.js and npm versions...'
                sh 'node -v' // Verify Node.js is on PATH
                sh 'npm -v'  // Verify npm is on PATH
                echo 'Installing Bruno CLI globally...'
                sh 'npm install -g @usebruno/cli' // Install Bruno CLI
                sh 'bru --version' // Verify Bruno CLI installation
            }
        }
        stage('Run API Tests') {
            steps {
                // Ensure Node.js is available if this stage runs in a separate context
                tool 'Node.js 18'
                echo 'Executing Bruno API tests...'
                // Run tests with 'ci' environment and generate an HTML report
                sh 'bru run --env ci --reporter-html results.html'
            }
        }
        stage('Archive Test Results') {
            steps {
                echo 'Archiving test report...'
                // Save the generated HTML report as a build artifact
                archiveArtifacts artifacts: 'results.html', fingerprint: true
            }
        }
    }
    post {
        // Actions to run after the main pipeline stages complete
        always {
            echo 'Pipeline finished.'
        }
        success {
            echo 'API Tests Passed Successfully!'
        }
        failure {
            echo 'API Tests Failed! Check console output for details.'
        }
    }
}

Step 4: Configure Jenkins Pipeline Job

  1. Create a New Jenkins Job:
    • From the Jenkins Dashboard, click New Item.
    • Enter an Item name (e.g., bruno-api-tests-pipeline).
    • Select Pipeline as the item type and click OK.

Screenshot 2025-06-26 at 11.52.16 AM


  1. Configure Job Details:
    • In the job configuration page, navigate to the Pipeline section.
    • Set Definition to Pipeline script from SCM and Choose your SCM (e.g., Git).
    • Enter your Repository URL (e.g., https://github.com/your-org/your-repo.git).
    • Specify any Credentials if your repository is private.
    • Set Branches to build to */main (or the branch containing your Jenkinsfile).
    • Ensure Script Path is Jenkinsfile (this is the default).
    • Optional: Under Build Triggers, configure how you want your pipeline to start (e.g., GitHub hook trigger for GITScm polling for automatic builds on push, or Build periodically for scheduled runs using cron syntax).
  2. Click Save to finalize your job configuration.

Screenshot 2025-06-26 at 11.57.15 AM

Step 5: Run and Monitor Your Pipeline

  1. Trigger a Build:
    • From your Jenkins pipeline job page, click Build Now (in the left-hand menu) to manually start the pipeline.
  2. Monitor Progress:
    • Observe the Build History section to see the status of your builds (green checkmark for success, red cross mark for failure).
    • Click on a specific build number, then select Console Output to view real-time logs and detailed execution steps.
  3. View Test Results:
    • Once a build that generated results.html completes, navigate to that specific build's page.
    • Look for the Artifacts section (usually on the left sidebar or at the top of the build summary).
    • Click on results.html to download the report, then open it in your web browser for detailed test outcomes.

Screenshot 2025-06-26 at 12.00.32 PM


πŸ”— Try the Demo Yourself

We’ve published the full working collection on GitHub. You can either clone this or simply click the Fetch in Bruno button below!

 

Wrap Up

Automating your API testing workflow can save a lot of time for software developers and QA engineers and cost for a organizations. Instead of repeating one task multiple times, you can automate with Bruno CLI and Jenkins to build robust, bug-free, and quality software applications.

Want to explore more about API automation, security, and AI? Join the Bruno Discord Server to connect, learn, and grow with a vibrant tech community!