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.
- Create a *.medium, Ubuntu EC2 instance with
20GB
disk.
- Connect to your instance, install java by
sudo apt update
sudo apt install openjdk-11-jre
- Download and install Jenkins as described here.
- 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
- Install
kubectl
.
- Install Git if you don’t have.
- 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.
- Open port
8080
and visit your Jenkins server via http://<static-ip>:8080
and complete the setup steps.
- 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
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.
- Use your docker project GitHub repo, or create a new GitHub repository for which you want to integrate Jenkins.
- 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.
- 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.
- Choose the following events to be sent in the webhook:
- Pushes
- Pull requests