Jump to Content
API Management

Six essential tips for automating API delivery with CI/CD pipelines

July 21, 2023
Sai Saran Vaidyanathan

Technical Solutions Consultant

Varun Krovvidi

Product Marketing Manager, Google Cloud

In modern software development, automating delivery using Continuous Integration and Continuous Deployment (CI/CD) pipelines draws parallels to automotive assembly lines that doubled the production while cutting down costs by 65%. According to a recent report from Postman, over 51% of respondents indicated that their organizations devote more than half of their development efforts to APIs. APIs are a big part of development, so let's explore why you should integrate them into your CI/CD pipelines. We will also share best practices and tools for integrating Apigee within your organization's CI/CD processes.

4 reasons to automate your API delivery with CI/CD pipelines

Apigee is a feature-rich API management platform that provides developers with the necessary tools to build, secure, manage, and publish APIs. But what if you want to automate the process of deploying your APIs to Apigee? That's where CI/CD comes in. By incorporating Apigee into your CI/CD pipeline, you can automate API deployment, promote consistency across environments, and monitor API performance in real-time. Four of these benefits include:

  • Cut time to market by and respond faster to customer demands by automating API deployments.

  • Catch defects earlier and improve API security by automating the process of testing and securing APIs.

  • Slash costs by saving on staffing, tools, and infrastructure required to deploy and manage APIs.

  • Improve visibility and compliance by tracking and auditing API usage.

Key tools and useful tips to effectively automate API delivery and management

Integrating API delivery into CI/CD pipelines using products like Cloud Build streamlines the development process. For example, a developer building an application on Google Cloud can deliver APIs side by side with other workloads in tools such as Cloud Run, Google Kubernetes Engine (GKE), Cloud Functions, and  App Engine.

Operational automation can include a list of seemingly endless aspects of the development process. But at a high-level, the key components of an effective CI/CD pipeline for API management  include:

1. Building and testing API proxies

  • If you are new to Apigee, utilize the comprehensive visual tools in the console to build and deploy API proxies using a convenient drag and drop interface. You can elevate their API proxy development by leveraging the VS Code extension and Apigee Emulator. This local setup enables you to use auto-complete features along with local proxy deployment, testing, and seamless code commit to trigger the pipeline for further deployment across Apigee environments.

  • Useful tip: Maximize the utility of Apigee, use the Debug tool to inspect every detail of an API transaction. Lastly, remember to export your proxy from the Apigee console and commit it to your source repository. With these best practices in hand, you're all set to make the most of your Apigee journey.

2. Store and version your API code: 

  • Ensure robust source code management – foundation of every CI/CD pipeline – to easily track, and manage changes. Use Cloud Source Repositories, a fully managed Git repository for seamless integration with other GCP development (or) leverage common tools like GitHub, GitLab, BitBucket and many more depending on your organization’s approach

  • Useful tip: Employing the right branching strategy helps reduce complexity and keeps delivery lean. Check out this community post for different branching strategies and choose the right one for your use case. Ensure frequent commits and merges to your source code to keep your codebase healthy and up-to-date. Regular code reviews also help refine your code and create quality checkpoints.

3. Ensure code quality with static code analysis:

  • Regular static code analysis can help you to improve the quality of your code by detecting potential errors and security vulnerabilities. It can also help you to promote code standardization by ensuring that your code follows a consistent style. For static code analysis you can use apigeelint (for analyzing Apigee bundles), JSHint and ESLint (for JavaScript analysis), Checkstyle and PMD (for Java analysis), or SonarQube (for multi-language support)

  • Useful tip: Integrate the tool with your code editor so that you can see the results of the analysis as you write code. Define quality gates/thresholds and run the tool as part of your build pipeline. Mark the build as failed if it does not meet the thresholds.

4. Ensure code resilience with unit testing and Code coverage: 

  • Unit tests focus on individual units of code, such as methods or classes. They help to ensure that each unit of code works as expected. Code coverage measures the percentage of code that is covered by unit tests. A high code coverage percentage indicates that more of your code is being tested, which can help to reduce the risk of errors. You can use these tools for unit testing and code coverage: Mocha and Chai (for JavaScript), JUnit (for Java), Cobertura and Istanbul (nyc) (for code coverage)

  • Useful tip: Write unit tests for all of your code. This includes both new code and existing code. Run unit tests during the build process. This will help to ensure that your code is always passing unit tests before it is deployed. Set coverage thresholds and mark the build as failed if it does not meet the thresholds. This will help to ensure that your code is sufficiently covered by unit tests.

5. Configure, Package and Deploy your code:

  • Creating a successful API deployment is like constructing a sturdy building. You need a strong blueprint (your Apigee code) that has been carefully planned, packaged into a deployable format (a zip file), and then implemented (imported into Apigee and deployed to an Apigee environment). During the packaging phase, the blueprint is detailed with metadata and manifest, similar to labeling and preparing architectural plans for construction. Moreover, all your Apigee configurations, except sensitive info, can be integrated into your blueprint, ready to be brought to life with the right tools. In terms of tooling, you can choose from a variety of open-source options that are built on Apigee APIs. Some of the commonly utilized ones are Apigee Deploy Maven plugin, apigee cli, apigee-sackmesser, and custom scripts using the Apigee APIs.

  • Useful tip: Use an artifact system to store these bundles. This will make it easy to manage and track your bundles. Maintain all the necessary configurations like Target server, Key Value Map, etc as part of the source code repo. This will make it easier to deploy your code to different environments. Use the pipeline and the source code to promote the proxies from lower environments to production. This will help you to ensure that your code is always up-to-date in production.

6. Verify the changes with Functional or integration testing:

  • Consider integration testing as a rigorous dress rehearsal for your API’s debut performance. It's your chance to verify if your API plays its part flawlessly under various scenarios, including when it has to share the stage with third-party systems. To ensure the API is working as expected, you have some powerful tools at your disposal such as Apickli (based on cucumber.js), Postman, and JUnit

  • Useful tip: Manage these tests as part of the source code and run different test suites based on the environment deploying to. This will make it easy to track and manage your tests. Run these tests right after the deployment and mark the build as failed if it does not meet the threshold. This will help you to identify and fix any issues that may have been introduced during the deployment. Create rollout plans when the functional tests fail by rolling out to the previous working/stable version. This will help you to minimize the impact of any issues that may have been introduced during the deployment.

Additionally, here are some optional trail markers you can consider on your journey to perfecting your pipeline:

  1. Testing Your API's Endurance: Running performance tests ensures your API can withstand the long haul.

  2. Clear and Accessible Documentation: Keep your developer portal up-to-date with the latest API documentation. Tools like the Apigee Smartdocs Maven plugin can make this a breeze, particularly with the Drupal developer portal.

Here is a typical pipeline example with a comprehensive reference implementation we see with most of our customers. It triggers when the developer commits the code to the repo. The pipeline can be executed by any CI/CD platform like Cloud Build.

https://storage.googleapis.com/gweb-cloudblog-publish/images/1-cicdimage.max-1300x1300.png

Get started today

Why wait? Kickstart your Apigee journey today directly from the console or evaluate it for free. Leverage our Accelerators to jumpstart your development using examples or advanced technical guidance. Should you have any questions or need support along the way, our Apigee Community is teeming with experts ready to lend a hand.

Posted in