Set up Jenkins with an AWS instance and integrate it with GitHub

Set up Jenkins with an AWS instance and integrate it with GitHub:



Prerequisites:

An AWS account with EC2 instances for hosting Jenkins.

A GitHub account and a repository that you want to build and deploy with Jenkins.

Step 1: Launch an AWS EC2 Instance for Jenkins:


Log in to your AWS Management Console.

Launch an EC2 instance with an appropriate Amazon Machine Image (AMI) such as Amazon Linux or Ubuntu.

Configure security groups to allow SSH and HTTP/HTTPS access.

Connect to your EC2 instance using SSH.


Step 2: Install Jenkins on AWS Instance:

Update the instance packages: sudo yum update (for Amazon Linux) or sudo apt-get update (for Ubuntu).

Install Jenkins. The installation steps can vary depending on the Linux distribution. For example, on Ubuntu, you can use:


Copy this below code to install:


  1. Copy the below commands:
    wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add - sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list' sudo apt-get update & install jenkins
  2. Start Jenkins:
  3. sudo service jenkins start

Open your web browser and access Jenkins at http://YOUR_AWS_INSTANCE_IP:8080.

Step 3: Configure Jenkins:

During the initial setup, Jenkins will require you to enter an administrator password. Retrieve it from your AWS EC2 instance using the following command: sudo cat /var/lib/jenkins/secrets/initialAdminPassword.

Follow the setup wizard to install recommended plugins and set up your admin user.

Step 4: Install and Configure Necessary Plugins:

Install plugins required for your specific project, such as GitHub Integration, AWS plugins, and any build tools.

Configure the GitHub plugin with your GitHub credentials.

Step 5: Create a Jenkins Job:

Click on "New Item" to create a new Jenkins job.

Choose the type of project (e.g., Freestyle project or Pipeline).

Configure your job to pull the source code from your GitHub repository, define build and deployment steps, and configure triggers for automation.

Step 6: Set Up Webhooks in GitHub:

In your GitHub repository, go to Settings -> Webhooks.

Add a new webhook that points to your Jenkins instance, including the payload URL and the events that trigger the webhook.

Step 7: Test Your CI/CD Pipeline:

Push code changes to your GitHub repository to trigger the Jenkins job.

Monitor the Jenkins build process, and review the logs and artifacts.

 

 

Comments