Skip to main content
Integration tests ensure that individual components in your application communicate correctly when combined. This guide shows how to add an integration testing stage to a Jenkins Pipeline for a Kubernetes-based system using simple curl commands.

What You Will Learn

  • How to verify HTTP response codes and payloads with curl
  • Embedding integration tests in a Jenkinsfile
  • Rolling back failed deployments automatically

Why Integration Testing Matters

Integration testing catches issues that unit tests cannot, such as network connectivity, misconfigured services, or data serialization errors. For a REST API, common checks include:
  • HTTP status codes
  • Response headers
  • Payload validation (JSON, XML, or plain text)

Architecture Overview

Our demo application consists of two microservices:
  1. A Spring Boot service listening on a NodePort (e.g., 31933)
  2. A Node.js service that processes business logic
The Spring Boot service forwards requests to the Node.js service. We will run two curl-based tests:
  1. Check that /increment/99 returns HTTP 200
  2. Confirm payload increments 99 to 100
The image is a diagram explaining integration tests for a Kubernetes-based application, showing the interaction between a Spring Boot microservice and a Node.js microservice. It includes details about ports, endpoints, and the testing focus areas like HTTP response codes and payloads.

Manual Curl Commands

Use these commands for a quick sanity check:

Embedding Integration Tests in Jenkins Pipeline

Add a dedicated Integration Test - DEV stage right after deploying to Kubernetes. The stage will:
  • Execute integration-test.sh for curl-based checks
  • Automatically roll back on failure using kubectl rollout undo

Jenkins Pipeline Stages at a Glance

Jenkinsfile Snippet

Ensure that the serviceName environment variable matches your Kubernetes Deployment name. Replace ${serviceName} if needed.

integration-test.sh Script

Create an integration-test.sh file with executable permissions (chmod +x integration-test.sh):

Local Testing

Before committing to Jenkins, validate tests locally:
If you see 200 and 100, your integration test script is working.
After pushing changes, Jenkins will run the updated pipeline, including the new integration test stage.
The image shows a Jenkins pipeline for a "devsecops-numeric-application," detailing various stages such as building, testing, scanning, and deployment, all marked as successful. A person is visible in the top right corner.

References

Thank you!

Watch Video