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

Make sure you have docker installed in your host system

1. GITHUB
First we need to create repository

Then create name your repository make it Public access

Then we are ready to craete new repository
After repository created, click
create new repository
Just create new file
Readme.md fill it with description project and commit changes to save it 
The commit message we can set is as default

then we can see in our repository have a file named Readme.md

then we can clone the repository

Login Git
Method with SSH
Generate SSH Key

Store
~/.ssh/id_rsa.pub in githubCopy all content of file id_rsa.pub and store it into github

Go to repository and settings

Select
Deploy Key
Paste content .pub and save with click
add key dont forget to checkmark Allow Write Access
Test the connection

Now my github account connected with my server
Git Clone
Click
code copy links SSH
then we clone it to our Ubuntu Server

If success its will create new repository and check folder with command
then go to inside repository and check the file

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

write in docker-compose
create new folder and create new file
index.htmlfill with
Hello yourname or something
then save it.
Here's how to commit and push your changes to a Git repository:
- Stage Changes: Add the files you want to commit (use
.to add all changes).
- Commit Changes: Create a commit message describing your changes.
- Push to Remote Repository: Send your commit to the remote Git repository.

now you can check into your github page

There its, we have successfully update into our Github repository

2. Docker Container
go to your repository directory run the container

make sure the container running, container nginx will run on port 8080

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
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-Nginxand deploy apps

to more detail installing jenkins you can check in my post Install Jenkins

Add Plugins
Click
Manage Jenkins
Click
Plugins

Go to
Available Plugins search SSH Agents and click Check box then click Button Install
Scroll Down and Click Checkbox
Restart Jenkins
After Success restart we can make sure SSH Agents installed or not in Installed Plugins

There its, My SSH Agent is success installed, then return to Dashboard . We are ready to create our first pipeline

Create Pipeline
Click New Item

Input Name CICD and Select
Pipeline
after OK you need to Configure the CICD, Scroll down and find pipeline, Change it into
Pipeline script from SCM
Add your repository URL, use the HTTPS and branch change to
*/main
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

Name file with
Jenkinsfile
write Jenkinsfile

here is the code
save it / Commit changes

after saved now in our repository is have Jenkinsfile

ok now, back to Jenkins Page
Try click
build now 
its will trigger new builds. if its green then its success. try to click it

if you click Builds #2 you will get more detail about pipeline

Lets check the
Console Output
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 JenkinsfileI am add
Test Echo 2 into Jenkinsfile, you can edit Jenkinsfile from Github. Just click Jenkinsfile and click pencil to edit 
Click Edit

Commit Changes to save it

Back again to Jenkins page, and hit
Build now again
OK after Build now Clicked in Builds will increased, and check again the Console Output

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

Click
Global and Add Credentials
Select
SSH Username and private key
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
next for private key click
Add
copy private key from

Copy all text to the very bottom text
-----END OPENSSH PRIVATE KEY-----paste into Jenkins

ok, click Create to save it

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

after saved lets
Build now again in jenkinsannddd

Hereee we are, its success SSH to VM and run command
hostnamectl is successLets implement it to deploy app using nginx html
.png?table=block&id=140c8d32-c2c2-809f-8396-f3564e6848df&t=140c8d32-c2c2-809f-8396-f3564e6848df&width=707.984375&cache=v2)
The flow will look like these
- Developer Commit code to Github
- Github Trigger Build Jenkins
- 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

Edit and add change code then save it
and save it to git to save changes

then lets go to our jenkins to start
build now
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
Deploy Docker App
after add pull repository in jenkins we add deploy docker stages in jenkinsfile

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

then commit it
back again to Jenkins and hit
Build Now
and if green then its success

and check to our nginx app in port 8080

there its, its updated
today is saturday- Author:samuraixheart
- URL:https://blog.abdulazizm.my.id/article/simple-cicd-jenkins
- Copyright:All articles in this blog, except for special statements, adopt BY-NC-SA agreement. Please indicate the source!






