CI/CD pipeline on AWS with Jenkins and CodeDeploy

  1. Create an IAM User:

    • Go to the IAM console in AWS.

    • Create a new user with programmatic access.

    • Attach the policy AmazonS3FullAccess and other necessary policies for CodeBuild and CodeDeploy.

    • Record the Access Key ID and Secret Access Key.

  2. Create an S3 Bucket:

    • Navigate to the S3 console and create a bucket.

    • Record the bucket name and URL.

  3. Launch an EC2 Instance:

    • Use AWS Linux AMI for simplicity.

    • Record the Instance ID once the instance is running.


Step 2: Configure CodeBuild and CodeDeploy

  1. Set Up a CodeBuild Project:

    • In the AWS Developer Tools console, create a new CodeBuild project.

    • Choose "No source" since the source will be handled by Jenkins.

    • Use a managed environment with Amazon Linux OS.

    • Create and attach a service role for CodeBuild and record its name.

    • Specify your S3 bucket for build artifacts (e.g., codebuild-artifact.zip).

  2. Set Up CodeDeploy Configuration:

    • In the CodeDeploy console, create a deployment configuration.

    • Select EC2 as the compute platform.

    • Enable cloud logging if needed for debugging.

    • Record the deployment configuration name.


Step 3: Configure Jenkins Job

  1. Install Plugins:

    • Install the following plugins in Jenkins:

      • File Operations

      • AWS CodeBuild

      • HTTP Request

  2. Create a Jenkins Job:

    • Build Step 1: AWS CodeBuild

      • Enter your IAM credentials, CodeBuild project name, and AWS region.

      • Select "Use Jenkins Source."

    • Build Step 2: Clean Environment (File Operations - Delete)

      • Delete all files (*) to ensure a clean build environment.
    • Build Step 3: Download Build Artifact (HTTP Request)

      • Construct the S3 URL using your bucket name and artifact name (e.g., https://<bucket-name>.s3.<region>.amazonaws.com/codebuild-artifact.zip).

      • Configure advanced options:

        • Timeout: 0

        • Expected Response Codes: 100-399

        • Output Response to File: codebuild-artifact.zip

    • Post-Build Steps:

      • Use File Operations to unzip the downloaded artifact and delete the .zip file.

      • Deploy to AWS CodeDeploy using the saved configuration.