Lazy loaded image
♾️Simple CICD with Jenkins
Words 1752Read Time 5 min
Apr 29, 2025
Jun 4, 2025
type
status
date
slug
summary
tags
category
icon
password

What is CICD ?

CI/CD stands for Continuous Integration and Continuous Deployment (or Continuous Delivery), a set of practices in DevOps to automate software development and deployment. It helps teams release software more frequently, reliably, and efficiently. Here’s a breakdown:

1. Continuous Integration (CI)

  • In CI, developers regularly merge their code changes into a central repository. Automated tests run on each change to verify it works and doesn’t break the main codebase.
  • This practice detects issues early, making them easier and cheaper to fix.

2. Continuous Delivery (CD)

  • Continuous Delivery ensures that every change that passes the CI process is automatically prepared for release to production.
  • Although deployment can be automated or manual, the goal is to keep code in a release-ready state.

3. Continuous Deployment (CD)

  • Continuous Deployment takes Continuous Delivery a step further. Every code change that passes tests is automatically released to production without manual intervention.
  • This practice is common for web applications where frequent updates are expected.

Benefits of CI/CD:

  • Faster release cycles and quicker feedback on code.
  • Reduced bugs due to automated testing.
  • Easier collaboration among developers.
  • Increased stability in production environments.
 
CI/CD is typically managed using CI/CD pipelines, which automate building, testing, and deploying applications through tools like Jenkins, GitLab CI, CircleCI, and GitHub Actions.
 
So in this practice i will show simple CICD , the tech stack I will use is :
 
  • Jenkins
  • Docker
  • Nginx
  • Github
  • Ubuntu server 20.04
 
Server OS i am used
notion image
Make sure you have docker installed in your host system
notion image

1. GITHUB

First we need to create repository
notion image
Then create name your repository make it Public access
notion image
Then we are ready to craete new repository
After repository created, click create new repository
notion image
Just create new file Readme.md fill it with description project and commit changes to save it
notion image
The commit message we can set is as default
notion image
then we can see in our repository have a file named Readme.md
notion image
then we can clone the repository
notion image
 

Login Git

Method with SSH
Generate SSH Key
notion image
Store ~/.ssh/id_rsa.pub in github
Copy all content of file id_rsa.pub and store it into github
notion image
Go to repository and settings
notion image
Select Deploy Key
notion image
Paste content .pub and save with click add key dont forget to checkmark Allow Write Access
notion image
Test the connection
notion image
Now my github account connected with my server

Git Clone

Click code copy links SSH
notion image
then we clone it to our Ubuntu Server
notion image
If success its will create new repository and check folder with command
then go to inside repository and check the file
notion image
voila !!! there is a file that we created earlier before. You can check what is GIT and what is Github
Next i will show you create new files in our server and commit to my github

Commit Docker Compose

first create new file. make sure in cli directory is on your repository directory
notion image
write in docker-compose
create new folder and create new file index.html
fill with Hello yourname or something
notion image
then save it.
 
Here's how to commit and push your changes to a Git repository:
  1. Stage Changes: Add the files you want to commit (use . to add all changes).
    1. Commit Changes: Create a commit message describing your changes.
      1. Push to Remote Repository: Send your commit to the remote Git repository.
        1. notion image
      now you can check into your github page
      notion image
      There its, we have successfully update into our Github repository
      notion image

      2. Docker Container

      go to your repository directory run the container
      notion image
      make sure the container running, container nginx will run on port 8080
      notion image
      then check to your ubuntu IP:port-nginx
      in my case my ubuntu IP is 192.168.56.2 and nginx port used is 8080 so i will access 192.168.56.2:8080
      notion image
      why access using port 8080 ?
      in my docker compose its using
      so the port 8080 is used for access public, and port 80 is for networking internal inside docker. more info in Docker Docs
      after make sure deployment is success I will push it to Github
       
       

      Create CICD

      After setup github repository we are ready to create our first CICD, the first thing we need is JENKINS.
       

      Deploy Jenkins

       
      I am creating new folder for jenkins
      here is my docker compose
      so here is currently my directory looks like inside Simple-CICD-Nginx
      and deploy apps
      notion image
      🚧
      to more detail installing jenkins you can check in my post Install Jenkins
       
       
      notion image

      Add Plugins

      Click Manage Jenkins
      notion image
      Click Plugins
      notion image
      notion image
      Go to Available Plugins search SSH Agents and click Check box then click Button Install
      notion image
      Scroll Down and Click Checkbox Restart Jenkins
      notion image
      After Success restart we can make sure SSH Agents installed or not in Installed Plugins
      notion image
      There its, My SSH Agent is success installed, then return to Dashboard . We are ready to create our first pipeline
      notion image

      Create Pipeline

      Click New Item
      notion image
      Input Name CICD and Select Pipeline
      notion image
      after OK you need to Configure the CICD, Scroll down and find pipeline, Change it into Pipeline script from SCM
      notion image
      Add your repository URL, use the HTTPS and branch change to */main
      notion image
      thennnn save it !!! oke, the pipeline is ready. but we are missing crucial step its the Jenkinsfile script. In Jenkinsfile you describe how the CICD flow, first lets test to create Test Jenkinsfile
       

      Create Test Jenkinsfile

      I am showing add file from github, its will more easy to edit the text from github right know.
      Back to your github add file
      notion image
      Name file with Jenkinsfile
      notion image
      write Jenkinsfile
      notion image
      here is the code
      save it / Commit changes
      notion image
      after saved now in our repository is have Jenkinsfile
      notion image
      ok now, back to Jenkins Page
      Try click build now
      notion image
      its will trigger new builds. if its green then its success. try to click it
      notion image
      if you click Builds #2 you will get more detail about pipeline
      notion image
      Lets check the Console Output
      notion image
      Hey there is an output from echo 'Hello, this is a test pipeline!' its from Jenkinsfile that writed before. its mean the Jenkinsfile is running successfully for step Test Echo lets try add new steps in Jenkinsfile
      I am add Test Echo 2 into Jenkinsfile, you can edit Jenkinsfile from Github. Just click Jenkinsfile and click pencil to edit
      notion image
      Click Edit
      notion image
       
      Commit Changes to save it
      notion image
      Back again to Jenkins page, and hit Build now again
      notion image
      OK after Build now Clicked in Builds will increased, and check again the Console Output
      notion image
      Hey there its, its my new step Test Echo 2 . OK so i am assumed you are already know how Jenkinsfile works. Next step is I will show how to Automate Trigger build, and deploy to our VM.
       

      Setup SSH

      Since the CICD will ssh into VM we need to add credentials in Jenkins. Click profile then Click Credentials
      notion image
      Click Global and Add Credentials
      notion image
      Select SSH Username and private key
      notion image
      since we are already create ssh key, we can use it again
      in ID type ssh-to-vm and username is the username of your VM, in here i will use kazami
      notion image
      next for private key click Add
      notion image
      copy private key from
      notion image
      Copy all text to the very bottom text -----END OPENSSH PRIVATE KEY-----
      paste into Jenkins
      notion image
      ok, click Create to save it
      notion image
      ok before run the pipeline we need to add SSH key into authorized_keys to do it just write pub key into authorized_keys, with doing these its allowing SSH into server without using password
      If not doing this in SSH step will got error permission denied
      Lets add new Steps in Jenkinsfile
      Full code Jenkinsfile will look like these
      Commit to github to make changes, in Jenkinsfile github will look like these
      notion image
      after saved lets Build now again in jenkins
      annddd
      notion image
      Hereee we are, its success SSH to VM and run command hostnamectl is success
      Lets implement it to deploy app using nginx html
      notion image
      The flow will look like these
      1. Developer Commit code to Github
      1. Github Trigger Build Jenkins
      1. Jenkins start CICD (Pull Repository, SSH to VM, Deploy App in docker
       
      Ok lets start
      In earlier we are already create index.html and already commited to github. We are need to create Jenkinsfile for first step
       

      Pull Repository

      notion image
       
       
      Edit and add change code then save it
      and save it to git to save changes
      notion image
      then lets go to our jenkins to start build now
      notion image
      and new builds will run
      and check the output if look like these cd ~/Simple-CICD-Nginx and git pull origin main its mean success
      notion image
       
      Deploy Docker App
      after add pull repository in jenkins we add deploy docker stages in jenkinsfile
      notion image
      add new stages
      and we are already add new Stage, before commit add new code to index.html
      add new code in index.html write anything you want and save it
      notion image
      then commit it
      back again to Jenkins and hit Build Now
      notion image
      and if green then its success
      notion image
      and check to our nginx app in port 8080
      notion image
      there its, its updated today is saturday
       
       
      上一篇
      Vault Secret Centralized
      下一篇
      Create Virtual Machine With VirtualBox