My First DevOps Project On- Jenkins CICD with GitHub Integration
Jnanesh E.
Senior DevOps Engineer at Aptean | Platform Engineering | Azure | AWS | Cloud & Automation Enthusiast ?? |
Jenkins CICD with GitHub Integration
Step 1) Create AWS EC2 instance - Jenkins_server
********Install and configure Jenkins**********
sudo apt-get update
sudo apt install openjdk-11-jre
sudo wget -O /usr/share/keyrings/jenkins-keyring.asc https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
sudo wget -O /usr/share/keyrings/jenkins-keyring.asc https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian-stable binary/ | sudo tee /etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update
sudo apt install openjdk-11-jre
sudo apt-get update
sudo apt install openjdk-11-jre
sudo apt-get install jenkins
sudo apt-get update
jenkins --version
sudo systemctl enable jenkins
sudo systemctl start jenkins
sudo systemctl status jenkins
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Enable 8080 port on EC2 server
Copy admin password and paste it on Jenkins --> 3.25.221.181:8080
Install suggested plugins
User name: jnanny
Password : Jnanny@95
New Item
` Name : To-Do Node app
Select Freestyle project
Description
This is to-do node app
Select Github Project
Project URL : https://github.com/JnaneshJnanny/node-todo-cicd.git
Source code Management
Git [*]
Repository URL
Create SSH key in jenkins server
sshkey-gen
cat /home/ubuntu/.ssh/id_rsa.pub
Copy public key
Add public key in to gihub account
Profile --> Settings --> SSH and GPG Keys --> New SSH key --> Title : Jenkins project
Paste public key
sdifsf3238479423423
Jenkins Credentials Provider: Jenkins
Add Credentials
Select Jenkins
Kind: SSH User name and private key
ID : github-kenkins
Description : Jenkins and github integration
User name : ubuntu
Private Key
Enter directly : Paste
cat /home/ubuntu/.ssh/id_rsa
Copy entire private key
Add
Credentials : Select added one
Branches to build
Branch Specifier (blank for 'any') : master/main (check your branch name)
Click Save
Build now : Build will successful
Now configure and to-app in jenkins manual method :
Check read me file in repository
Run these commands:
sudo apt install nodejs
领英推荐
sudo apt install npm
npm install
npm install express
Go to path : cd /var/lib/jenkins/workspace/To-Do Node app
node app.js
Add 8000 port in jenkins server
*****************Automating with docker *************
Install Docker on jenkins server
sudo apt install docker.io
vi Dockerfile
FROM node:12.2.0-alpine
WORKDIR app
COPY . .
RUN npm install
RUN npm run test
EXPOSE 8000
CMD ["node","app.js"]
sudo docker build . -t to_do_app
docker images
sudo docker run -d --name node-todo-app -p 8000:8000 22a4f11408ee (Docker ID)
sudo docker ps
Open in Browser : https://3.25.221.181:8000/todo
Stop or kill running container
**********Congrats your app is running through docker**********************
Now automate with jenkins
Jenkins---> Dashboard --> To-Do Node app -- >Configuration --> Build environment
Add build step --> Execute shell --> Save
For Permission denied error : Run this in jenkins server:
sudo usermod -a -G docker jenkins
sudo systemctl restart jenkins
Build Now
Error will resolve now
Note: remove all existing container befire build
**********Now automate with github (No need to build manually) ****************
Whenever developer push the code , That will build automatically using WEBHOOK
Install github integration plugin in jenkins
Manage jenkins --> Plugins --> available plugins -- > github integration --> Install
Go to guthub repo--> Settings --> webhooks (Before check ssh key presence)
Webhook --> Add webhook --> payload URL :https://3.25.221.181:8080/github-webhook/ (jenkins) --> Add webhook
Content type : Application JSON
******************Configure Jenkins again***********************
To-do-node app --> Configure -- > Build trigger --> GitHub hook trigger for GITScm polling [*] --> Save
Now make some changes in code to check
Go to repo --> views/todo.ejs --> Made some chnages in title --> Commit changes
Openshift/Kubernetes Administrator
1 年Nice document..
Openshift/Kubernetes Administrator
1 年@