Skip to main content
In our previous guide, we deployed a Docker image to an AWS EC2 instance. Now, we’ll enhance our Jenkins pipeline with an Integration Testing stage that dynamically discovers the EC2 instance’s public endpoint and performs HTTP checks against our service.

Prerequisites

  • Docker container running on EC2 (port 3000)
  • AWS CLI configured with permissions to ec2:DescribeInstances
  • jq and curl installed on the Jenkins agent
  • Jenkins credentials (AWS Access Key & Secret) stored (e.g., ID aws-s3-ec2-lambda-creds)
Ensure your EC2 instance is tagged with Name=dev-deploy. This tag is used to filter and locate the instance dynamically.

1. Verify the Running Container

Log into your EC2 instance and confirm the application is up:

2. Create the Integration Test Script

At the root of your Git repo, add integration-testing-ec2.sh:
Make it executable:

3. AWS CLI: describe-instances

We use the AWS CLI’s describe-instances to list EC2 instances and filter by tag.
The image shows a webpage from the AWS CLI Command Reference, specifically the documentation for the "describe-instances" command. It includes a table of contents, a note about AWS CLI versioning, and a description of the command's functionality.
Example JSON snippet:
We extract .PublicDnsName where .Tags[].Value == "dev-deploy" using jq.

4. Integrating with Jenkins Pipeline

We’ll add a new stage Integration Testing – AWS EC2 in the Jenkinsfile:
  1. Trigger on feature/* branches
  2. Use withAWS (AWS Pipeline Steps plugin) for credentials and region
  3. Execute our shell script
Store your AWS credentials securely in Jenkins Credentials. Never hard-code keys in your Jenkinsfile.

Credentials Setup

The image shows a Jenkins dashboard displaying a list of stored credentials, including IDs and names for various services like MongoDB, Gitea, and AWS.

Generate withAWS Snippet

Use Jenkins’ Pipeline Syntax to obtain:
The image shows a Jenkins Pipeline Syntax configuration page, where AWS settings are being set for a nested block, including fields for region, endpoint URL, and credentials.

Jenkinsfile Stage

5. Pipeline Execution & Results

After pushing changes, the new stage runs automatically. Here’s a successful pipeline:
The image shows a Jenkins pipeline interface for a project named "solar-system," displaying various stages of a build process, with most stages completed successfully. The integration testing section provides details on specific tasks and their statuses.
Log excerpt:

6. Summary of Endpoints Tested

With this setup, each commit on a feature branch dynamically locates the EC2 instance, verifies service health, and enforces basic integration tests before completing the pipeline.

References

Watch Video