Apidog

All-in-one Collaborative API Development Platform

API Design

API Documentation

API Debugging

API Mocking

API Automated Testing

How to Integrate Apidog Automated Testing with Jenkins for CI/CD

This article primarily focuses on integrating Apidog automated testing with Jenkins, detailing the specific steps involved.

@apidog

@apidog

Updated on November 5, 2024

The primary goal of CI/CD (Continuous Integration/Continuous Delivery) in API testing is to automate the verification process, ensuring that APIs are functional and ready for production before deployment. With continuous integration, we can automatically execute functional tests whenever modifications are made to API definitions, allowing for the early detection of potential issues.

Apidog supports integration with various CI/CD platforms, including Jenkins, GitLab, and GitHub Actions. You can find integration code snippets in the CI/CD module of automated testing in Apidog. By adding these snippets to your CI/CD workflow, you can seamlessly incorporate Apidog automated testing into your existing CI/CD processes.

This article primarily focuses on integrating Apidog automated testing with Jenkins, detailing the specific steps involved.

button

Step 1: Install Jenkins

You can refer to the official Jenkins documentation for installation instructions tailored to different operating systems.

Install Jenkins

Once installed, you can acce ss the Jenkins visual interface through http://{your-public-IP}:8080.

 Jenkins visual interface

Configure Jenkins for Apidog CLI Command Execution

Configure Node.js Environment

Install the NodeJS Plugin

From the Jenkins management page, click on “Manage Jenkins,” then select “Manage Plugins” to enter the plugin management page.

Install the NodeJS Plugin

Under the “Available” tab, search for the NodeJS plugin, install it, and restart Jenkins.

Available Plugins

Configure NodeJS and Global npm Packages.

After the NodeJS plugin is installed, return to the “Manage Jenkins” page and select “Tools” to access the global configuration tools page.

Configure NodeJS and Global npm Packages

Locate the NodeJS module, click “Add NodeJS,” then enter a NodeJS alias (e.g., nodejs18), select a NodeJS version (must be greater than v14.20.1), and enter Apidog-cli in “Global npm packages to install.”

Check the “Install automatically” option to ensure the package is installed during the build process; then save your settings.

Create a Continuous Integration Pipeline

There are two methods to build a pipeline in Jenkins to achieve continuous integration: Pipeline and Freestyle Project. Below are the details for both methods.

1: Building a Pipeline

Create a Pipeline Project: On the Jenkins homepage, click “New Item,” enter a project name, select “Pipeline,” and click “OK.”

2. Configure the Pipeline:

In the project configuration page, locate the “Pipeline” option and select “Pipeline script” from the “Definition” dropdown menu.

Pipeline script

Enter the following Pipeline script from Apidog in the Script box and save the configuration.

pipeline {
  agent any

  tools {nodejs "nodejs18"}

  stages {
    stage('Install Apidog CLI') {
      steps {
        sh 'npm install -g apidog-cli'
      }
    }

    stage('Running Test Scenario') {
      steps {
        sh 'apidog run --access-token $APIDOG_ACCESS_TOKEN -t 605067 -e 1629989 -n 1 -r html,cli'
      }
    }
  }
}

This Pipeline script is available in the CI/CD module in Apidog Automated Testing.

The above Pipeline script can be simplified to something like this by removing the script that installs the Apidog CLI so that you don't need to install apidog-cli every time you perform a build, thus reducing build time and resource consumption. This is because the NodeJS and global npm packages (i.e. apidog-cli) are preconfigured in the Global Tools configuration, which ensures that the installed tools can be used directly during the build process.

pipeline {
  agent any

  tools {nodejs "nodejs18"}

  stages {
    stage('Running Test Scenario') {
      steps {
        sh 'apidog run --access-token $APIDOG_ACCESS_TOKEN -t 605067 -e 1629989 -n 1 -r html,cli'
      }
    }
  }
}

If you are using the newer version of the CI/CD command, which has a variable on the command line. You need to replace the variable $APIDOG_ACCESS_TOKEN with your actual available Access Token in your code. you can also add an environment variable called $APIDOG_ACCESS_TOKEN in Jenkins' “Dashboard -> Manage Jenkins -> System” and set its value to your Access Token. in Jenkins' “Dashboard -> Manage Jenkins -> System” and set its value to your Access Token, so that the system will be able to read your Access Token when executing the pipeline.

$APIDOG_ACCESS_TOKEN

3. Execute the Build

On the project page, click “Build Now” to start the execution pipeline.

Build Now

You can view the progress and results of a build in the Build History.

Build History


Building a Freestyle Project

  1. Create a Freestyle Project

On the Jenkins homepage, click “New Item,” enter the project name, select “Freestyle project,” and click “OK.”

Freestyle project

2. Configure Build Environment

In the project configuration page, under the “Build Environment” section, check “Provide Node & npm bin/ folder to PATH,” and select the NodeJS version you configured earlier (e.g., nodejs18).

Build Environment

3. Add Build Steps

After setting the build environment, navigate to the “Build Steps” section, click “Add build step,” and select “Execute Shell” (or “Execute Windows Batch Command” if on a Windows server).

Build Steps

Paste the Apidog CLI commands into the provided field and save your settings.

Paste the Apidog CLI commands

4. Execute the Build

Click "Build Now" on the project page to start the build process.

Execute the Build

Step 4: Sending Build Results to Third-Party Applications

The results of CI builds can be sent to third-party applications, such as Feishu or DingTalk. To configure notifications, go to Apidog’s Project Settings -> Notification Settings -> External Notification, where you can set up the desired notification events.

Frequently Asked Questions

  1. If there is a file in the interface that needs to be uploaded, how do I get that file at build time?

You can upload the required files to the machine running the CLI (i.e. the host where Jenkins is running) beforehand, e.g. this image file: images.jpg, by copying down the path to it.

images.jpg

Navigate to the API in Apidog that needs the file upload and click the “Bulk Edit” button.

Bulk Edit

Enter the file path to the uploaded file in the "Parameter Value" field, so that it automatically retrieves the actual file during the build.

Parameter Value

In addition, you can put the path to the file in the “Initate value” of the environment variable.

Initate value

Then in “Bulk Edit”, you can refer to the file path by variable, so that you can also get the actual file by the file path when you build it.

Bulk Edit

2. How to set up a timed build in Jenkins?

Apidog currently supports the use of timed tasks, please refer to the “Running Functional Tests Regularly” module in the help file, which is more friendly and convenient.

If you want to set up timed tasks in Jenkins, you can do it by configuring the “Build Triggers” of the project, and use Unix-like cron expressions to specify the time and frequency of the build.

On the Jenkins project configuration page, find the “Build Triggers” module, check the “Build periodically” option, and in the text box that appears, enter a cron expression to define the build time and frequency. In the text box that appears, enter a cron expression to define the time and frequency of the build, we won't go into details about the use of corn expressions here.

Build Triggers

Conclusion

This guide outlines how to integrate Apidog automated testing with Jenkins. Regardless of the chosen build method, ensure that the Apidog CLI is installed beforehand, either by automatic installation during the build or by pre-installation on the Jenkins host (using the command npm install -g Apidog-cli).

button
How to Set Assertions, Extract Variables, and Copy the JSON Path Directly in the Response Area When an Endpoint Returns a JSON Response in ApidogTutorials

How to Set Assertions, Extract Variables, and Copy the JSON Path Directly in the Response Area When an Endpoint Returns a JSON Response in Apidog

Learn how to effectively set assertions, extract variables, and copy JSON paths in Apidog when testing APIs that return JSON responses. Follow this step-by-step tutorial for a smooth API testing experience.

Ashley Innocent

November 20, 2024

Enhance API Documentation Search with Algolia IntegrationTutorials

Enhance API Documentation Search with Algolia Integration

Learn how to integrate Algolia with Apidog to enhance your API documentation search. This guide covers setup, best practices, and tips for a faster, more accurate search experience. Perfect for improving documentation usability and performance.

Oliver Kingsley

November 19, 2024

How to Effectively Troubleshoot API Error Issues with ApidogTutorials

How to Effectively Troubleshoot API Error Issues with Apidog

Master how to effectively troubleshoot API errors using Apidog. Discover it's powerful features like dynamic test case creation, automated testing workflows & built-in debugging tools to ensure smooth operation & reliable APIs.

INEZA FELIN-MICHEL

November 15, 2024