A Cloud Architect Company
Amazon Web Services

How to Set up Jenkins CI/CD Pipeline to Build and Deploy a ReactJS App from GitHub to Amazon S3

Introduction

In this article, we are going to cover a Jenkins CI/CD pipeline to build and deploy a reactjs app from github to amazon s3.

Jenkins is an open-source automation server that is widely used for building, testing, and deploying software projects. It provides a platform for implementing Continuous Integration (CI) and Continuous Deployment (CD) pipelines, allowing developers to automate various stages of the software development lifecycle.

If you would like to follow a video tutorial please use our YouTube video.

Prerequisites

GitHub Account: Ensure you have a GitHub account and a repository where your reactjs project is hosted.
AWS Account: An active AWS account with permissions to create and manage S3 buckets.
AWS S3 Bucket: Create an S3 bucket in your AWS account where you will deploy your project.
Jenkins Server: Install Jenkins on an EC2 instance or server.

Create IAM user

Go to IAM services, create a user with “EC2fullacess” and “S3fullaccess” permission. and download the access key and secret key

IAM user

Setup S3 bucket

Go to S3 services, click >> create bucket, type >> bucket name

S3 bucket

 

Unselect the >> block all access, select >> acknowledgement, click >> create bucket

S3 bucket

Now we successfully created the bucket, click >> properties

S3 bucket

Scroll down to see the static web hosting, click >> edit

static web hosting

Click >> enable, In index document type >> “index.html“, click >> save changes

Static web hosting

Now click >> permissions

S3 bucket

In bucket policy, click >> edit

s3 bucket

 

Now click >> policy generator

S3 bucket

In step 1 – select a type of policy, choose >> s3 bucket policy

In step2 – principle, type >> ” * “ , in AWS service, choose >> amazon S3, In actions,choose >>”GetObject“.

S3 bucket policy

In ARN go back to the previous page and copy the >> bucket ARN

s3 bucket

Paste the bucket ARN here and click >> add statement.

S3 bucket policy

Click >>  generate policy, copy the policy

S3 bucket policy

Go back to the previous page and paste the copied policy, add “/*” in the 11th line and click >> save changes

S3 bucket policy

Now we set all the things in the s3 bucket

Jenkins server

This is my Jenkins server, I already installed Jenkins, open the Jenkins server.

Jenkins

Click >> Create a job, add >> name,choose >> pipeline, click >> ok.

Select >> Github project, paste the GitHub project repository URL

Jenkins

In build triggers, select >> github hook trigger

Jenkins

In definition, choose >> pipeline script for SCM, In SCM choose >> git

jenkins

Add the github project repository url again, In credentials, click >> add , choose >> Jenkins

Jenkins

Choose >> AWS credentials (if it is not shown go to Jenkins main page, click manage jenkins, click plugin, and install AWS credentials plugin)

Jenkins

Add access key and secret key of the user that we created in the first step, and click >> add

Jenkins

Click >> apply and save

Jenkins

Now we successfully created a job, go to Jenkins main page, click >> manage Jenkins, and click >> credentials, here it will assign a credential id for the aws credentials, copy the credential id

jenkins

Setup Github

Go to github,add the credential id in the jenkins file

Github

To reference my Jenkins file, please consult the file “jenkinsfile” located in the root directory of this repository: https://github.com/easydeploy-cloud/jenkins-cicd-reactjs

Now add S3 bucket name in the jenkinsfile

Jenkins file

Now go to Jenkins server copy the public ip

Jenkins

 

Go to github repository settings, click >> webhooks, click >> add webhook

Webhooks

Now paste the jenkins ip here and type “/github-webhook” and click >> save

Webhook

Jenkins job

Go to Jenkins dashboard, click >> your job

jenkins

Click >> build now

jenkins

Now our project is successfully buildt and deployed in s3

Build jenkins

Web hosting

Go to S3 service, choose your bucket, click >> properties, scroll down, and copy the static web hosting url

Static web hosting

paste it in the new tab

React app

Now our React JS project is successfully built and hosted in the S3 web hosting

Now I am going to change some content to check if  the auto trigger is working properly or not

React app

Go to GitHub project repository,i am changing some words on the main page(app.js), click >> commit changes.

React js

The auto trigger is working properly, it successfully built the job and hosted it in the s3

Auto trigger deployment

Go to the react js page, click >> refresh button. Now the content has changed

React app

setting up a Jenkins CI/CD pipeline to build and deploy a ReactJS app from GitHub to Amazon S3 involves:

Configuring Jenkins with GitHub and AWS credentials.
Creating a Jenkins job to pull code from GitHub.
Building the ReactJS app.
Deploying the built files to an S3 bucket.

This automated process ensures efficient, reliable, and consistent deployment of your application, allowing your team to focus on development rather than manual deployments.

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

back to top
advanced-floating-content-close-btn

Contact Us to save your AWS bill by 40%

X