CI/CD With Jenkins: Part 1
A Continuous Integration and Continuous Delivery ( CI/CD ) Pipeline implementation is an important part of the modern DevOps environment. It bridges the gap between development and operations teams by automating the building, testing, and deployment of applications. Jenkins is an open-source tool to build a CI/CD pipelines.
In this article, I will share a step-by-step walkthrough on how you can host your Jenkins master node to configure your pipelines.
For this demonstration, I’m using the AWS EC2 instance and dockerized image of Jenkins to host our Jenkins master node. I assume all the firewall rules are preconfigured.
Note: Installing docker instructions on your machine can be found here.
You can find out dockerized Jenkins master repo on Github. Just clone the repo and follow instructions.
$ git clone https://github.com/prahveen/jenkins-master.git
$ cd jenkins-master
$ docker-compose up -d
If you have followed the above instructions, Jenkins should be up and running. Use this below command to verify further.
$ docker ps
Yes our Jenkins master node container is up and running.
Wait…! 🤔 Jenkins master node is running in our instance. Great…! But how can we access Jenkins over the internet. Let’s investigate into this.
Let’s start with adding a reverse proxy via nginx to access over the internet our Jenkins master, by installing nginx in our instance.
$ sudo apt install nginx
Once you install nginx, edit your nginx conf file. For this demonstration, I’m going to edit the default conf file. If you are editing the default conf file, it is always better to get a backup. 😀
$ sudo vim /etc/nginx/default
Replace the following in your conf file.
upstream jenkins {
server 127.0.0.1:8080 fail_timeout=0;
}server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/jenkins; index index.html index.htm index.nginx-debian.html; server_name _; location / {
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://jenkins;
# Required for new HTTP-based CLI
proxy_http_version 1.1;
proxy_request_buffering off;
proxy_buffering off;
}
}
Now restart nginx
$ sudo systemctl restart nginx
Boom! Now you can access Jenkins master node via internet
You can get your initial admin password from your Jenkins container
$ docker exec -it jenkinsmaster_jenkins_1 /bin/sh
$ cat /var/jenkins_home/secrets/initialAdminPassword
28d8b10580994647990b9893a8be1dde
Add your initial administrator password and then press continue. The next step, it will ask to install the required plugins.
If you do not have a clear idea of what packages you required to install, go with the suggested plugins. Once installation is done it will prompt to create an admin user account.
Once you create an admin user, restart Jenkins master node. Now you are good to go and you can access the Jenkins dashboard.
I hope this was helpful. If you still have any doubts, feel free to ping me on LinkedIn. In my next blog post I hope to write on how we set up CI/CD for our projects. Stay tuned!