Install Jenkins#
Jenkins is an automated build tool that helps developers automate building process, testing, and deploying applications during the software development process. Here's how to install it on a Linux system:1.
Add the Jenkins GPG public key:
2.
Add the Jenkins source to the list of APT software sources:
3.
Update the APT package list:
5.
Start the Jenkins service:
After installation, open a web browser and enter http://localhost:8080
or http://{your_public_IP}:8080
to access the Jenkins dashboard. The console provides a web API for you to manage and configure Jenkins services.Configuring Node.js environment for Jenkins#
Before running Apidog CLI, you need to ensure that the Node.js version number is v16 or later, so you need to configure NodeJS dependencies in the Jenkins environment first.
1.
Open the Jenkins plugin management and find the NodeJS plugin, install it and restart it.
2.
Create a new NodeJS in the global tool configuration, configure the version number (requires v16 or later) and package name apidog-cli
.
If apidog-cli has been installed on the Jenkins host and you want to run tasks directly in the Node environment, you can refer to the Node configuration in the figure below and fill in the Node path of the host.You can trigger Apidog automated tests in Jenkins using the following two methods:1.
Add the configuration in a visual pipeline (Freestyle Project)
2.
Integrate the embedded code into the pipeline (Pipeline)
Run CLI Commands#
Open Apidog and retrieve the CLI command from the Continuous Integration details page. If your Jenkins environment has internet access, you can choose to use the "Run online data in real time" command. If internet access is not available, you need to first export the CLI JSON data file into the environment and then execute it via the CLI.In the project configuration page, locate the Build Environment section, check the option "Provide Node & npm bin/ folder to PATH", and select the NodeJS version (e.g., nodejs18
) that you configured in the Global Tool Configuration (Tools) section.After setting up the build environment, go to the Build Steps section, click Add build step, and select Execute Shell (choose Execute Windows Batch Command if you're using a Windows system).Paste the Apidog CLI command into the Command input box and save the configuration.Click Build Now in the project to start the execution.You can check the build progress and results in the "Build History."Integrate Embedded Code into the Pipeline#
Navigate to the CI/CD tab and copy the embedded code snippet, then paste it into your Jenkins configuration file.Simply paste the code directly into the Jenkins pipeline configuration to embed it into your existing CI/CD workflow.The nodejs18
mentioned here refers to the NodeJS alias set earlier β please replace it with your actual alias. Also, make sure to replace the variable $APIDOG_ACCESS_TOKEN
in the code with your actual Access Token. Alternatively, you can add an environment variable named APIDOG_ACCESS_TOKEN
in Jenkins under Dashboard β Manage Jenkins β System, and set its value to your Access Token. This allows the pipeline to read your Access Token during execution.You can simplify the above code by removing the script for installing the Apidog CLI. This way, there's no need to reinstall apidog-cli
every time a build is executed, which reduces both build time and resource consumption. This is possible because NodeJS and global npm packages (i.e., apidog-cli
) have already been configured in advance under Global Tool Configuration (Tools), ensuring that the required tools are readily available during the build process.Click Build Now in the project to start the execution.Publish reports with Jenkins#
Specify the generated report name ${JOB_NAME}_${BUILD_NUMBER}
(Jenkins built-in variable) in the command. Use the HTML Publisher
plugin to view the report.