Jenkins is an incredibly ubiquitous tool for automating Continuous Integration/Continuous Deployment flows. API Fortress has gone through several iterations of integrating with this powerful platform. With the introduction of APIF-Auto, the integration flow has never been easier.
APIF-Auto, a command line tool that supports automated API Fortress test execution is an ideal tool for executing API Fortress tests in a Jenkins workflow. The pipeline script below serves as a template for creating a stage in your Jenkins Pipeline for testing your APIs with API Fortress. If you’d like to take a look at the documentation for APIF-Auto, click here.
sh ‘mkdir -p apifortress-reports’
Let’s break down what’s going on here! First, we’re telling Jenkins to create a new directory called ‘apifortress-reports.’ You can name this directory whatever you’d like, but there are a couple of important notes to remember:
First, remember the -p flag! It’ll keep the pipeline from overwriting the directory if it already exists in the future.
Second, remember the name! We’re going to need it later.
sh ‘python /path/to/apif-auto/directory/apif-run.py run-all demo -S -f junit -o apifortress-reports/apif.xml’
Next, we’re going to execute the actual test execution with API Fortress via APIF-Auto. We’re invoking the tool with python and the path to the tool. We’re passing a run-all argument for the project and credentials defined with the demo config key. The test is executing in sync mode, reporting in JUnit and outputting to apifortress-reports/apif.xml. If you notice, the output file is being placed in the directory we created in the previous step!
In this final step, we’re publishing the JUnit test report located in the directory that we established in the first step and called in the second step. By using the above workflow, we have a modular method of running API Fortress tests in authenticated mode in our Jenkins pipeline. By creating a modular flow, we have created something that we can reuse at multiple points in our DevOps lifecycle, keeping our overall codebase dry and reducing the amount of overall bandwidth we need to dedicate to automated API testing.