DevOpsBootcampUPES

CI/CD with Jenkins

Install Jenkins Server on EC2

Jenkins is typically run as a standalone application in its own process with the built-in Java servlet container/application.

  1. Create a *.medium, Ubuntu EC2 instance with 20GB disk.
  2. Connect to your instance, install java by
sudo apt update
sudo apt install openjdk-11-jre
  1. Download and install Jenkins as described here.
  2. On Jenkins machine, install Docker engine. You may want to add jenkins linux user the docker group, so Jenkins could run docker commands:
    sudo usermod -a -G docker jenkins
    sudo usermod -a -G docker $USER
    
  3. Install kubectl.
  4. Install Git if you don’t have.
  5. You’ll need your Jenkins server to have static public ip address. From the EC2 navigation pane, create an Elastic IP and associate it to your Jenkins instance.
  6. Open port 8080 and visit your Jenkins server via http://<static-ip>:8080 and complete the setup steps.
  7. In the Dashboard page, choose Manage Jenkins, then Manage Plugins. In the Available tab, search and install Blue Ocean and Docker Pipeline plugins. Then restart jenkins by http://<ip>:8080/safeRestart

Configure a GitHub webhook

A GitHub webhook is a mechanism that allows GitHub to notify a Jenkins server when changes occur in the repo. When a webhook is configured, GitHub will send a HTTP POST request to a specified URL whenever a specified event, such as a push to the repository, occurs.

  1. Use your docker project GitHub repo, or create a new GitHub repository for which you want to integrate Jenkins.
  2. To set up a webhook from GitHub to the Jenkins server, on your GitHub repository page, go to Settings. From there, click Webhooks, then Add webhook.
  3. In the Payload URL field, type http://<jenkins-ip>:8080/github-webhook/. In the Content type select: application/json and leave the Secret field empty.
  4. Choose the following events to be sent in the webhook:
    1. Pushes
    2. Pull requests