0% found this document useful (0 votes)
34 views69 pages

Jenkins Start To End

The document provides a comprehensive overview of Jenkins, an open-source automation tool for continuous integration and deployment. It covers key components such as jobs, triggers, and plugins, as well as installation instructions and examples for various projects including Node.js and Python. Additionally, it outlines the CI/CD pipeline workflow and the integration of Jenkins with other tools like GitHub and Docker.

Uploaded by

Pooja K N
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views69 pages

Jenkins Start To End

The document provides a comprehensive overview of Jenkins, an open-source automation tool for continuous integration and deployment. It covers key components such as jobs, triggers, and plugins, as well as installation instructions and examples for various projects including Node.js and Python. Additionally, it outlines the CI/CD pipeline workflow and the integration of Jenkins with other tools like GitHub and Docker.

Uploaded by

Pooja K N
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 69

Index

Why Jenkin ------------------ 2


Jenkin components ----------------- 3
Job ------------------ 5
Jenkin infrastructure ------------------ 6
First step toward Jenkin ------------------ 7
Update of Nodejs with freestyle project ------ 12
Docker Nodejs Jenkin -------- 32
Jenkin installation on Amazon linux ------- 44
Python Project freestyle -------- 48
CICD with nodejs --------- 60

1
Why Jenkins
Jenkin is a tool that is used for automation. It is mainly
an open-source service that allows all the developer to
build, test and deploy software.
By using Jenkin, we can make continuous integration of
project(jobs) or end-to-endpoint automation.
Main aim is Auto-update.
• Free and open source: Jenkins is free to use and can be
customized without licensing fees.

• Large community: Jenkins has a large, active community


that develops and shares plugins.
• Extensive plugin ecosystem: Jenkins has a large
ecosystem of plugins that can integrate with many other tools.
• Platform independent: Jenkins can be installed on many
operating systems and platforms.

• Scalable: Jenkins can be scaled up by adding nodes to run


builds on different machines.

• Integrates with many tools: Jenkins can integrate with


many tools in the software development lifecycle.

2
Jenkin components
• Jobs
• Triggers
• Plugins
• Configuration
• Security settings

Jobs/Projects
• Role: Defines the work Jenkins should perform.
• Types:
o Freestyle Jobs: Basic jobs with configurable build steps.
o Pipeline Jobs: Defined as code (Jenkins file) using Groovy.
o Multi-branch Pipelines: Automatically builds branches in
version control systems.

Triggers
Triggers automate the execution of jobs based on specific events or
schedules:
• Poll SCM: Periodically checks the repository for changes.
• Webhook Triggers: Triggers builds on push or pull request
events from GitHub/GitLab.
• Scheduled Trigger: Uses cron-like syntax for periodic builds.
• Build After Other Projects: Chains jobs together.
• Remote Trigger: Starts builds via API calls or scripts.

3
• Pipeline Triggers: Defined in Jenkinsfile using pollSCM or cron.

Plugins
• Role: Extend Jenkins' core functionality.
• Examples:
o Source Code Management (SCM): Git, SVN.
o Build Tools: Maven, Gradle.
o Deployment: Ansible, Kubernetes.
o Notifications: Slack, Email.
• Key Benefit: Modularity and flexibility in adapting to diverse
CI/CD needs.

Configuration
Proper configuration ensures Jenkins operates efficiently:
Website or webserver settings.
Two level: global level
Job level

Security settings
• Configured in Manage Jenkins > Configure Global Security.
• Includes authentication, authorization, and encryption settings.

4
Jobs
• Freestyle Job
• Pipeline
• Multibranch pipeline
Freestyle Job
• Simplest and most flexible job type.
• Configurable through the UI for tasks like compiling code,
running tests, or deploying applications.
• Supports basic build steps, triggers, and post-build actions.

Pipeline
• Automates workflows as code using a Jenkinsfile (written in
Groovy).
• Supports complex CI/CD processes with multiple stages (e.g.,
Build, Test, Deploy).
• Two syntaxes available: Declarative (simpler) and Scripted
(more flexible).

Multibranch Pipeline
• Automatically detects and creates pipelines for each branch in
a repository.
• Useful for managing CI/CD workflows for multiple branches in
Git or other SCMs.
• Handles feature branches, pull requests, and merges
dynamically.

5
Jenkin Infrastructure

This diagram represents a CI/CD pipeline workflow using Jenkins,


GitHub, AWS CodeBuild, S3, and CodeDeploy:
1. Push: Developer pushes code to GitHub.
2. Clone: Jenkins fetches code from GitHub.
3. Build: Code Build Plugin builds the project.
4. Artifact: The build generates an artifact (e.g., artifact.zip).
5. HTTP Request: Jenkins retrieves the artifact via HTTP.
6. File Operations: Artifact is unzipped or deleted.
7. Upload: Jenkins sends the artifact to an S3 bucket.
8. Deployment: Code Deploy Plugin deploys the application from
S3 to the target environment.
This setup integrates automation tools for seamless code building,
packaging, and deployment.

6
First Step towards Jenkin
Launch Ec2 instance.
sudo yum install docker.

sudo service docker start


sudo service docker status

mkdir jenkinvolume
ls

7
sudo su
docker run -d - - name Jenkins -v /home/ec2-
user/jenkinvolume:/varjenkins-home -p8080:8080 jenkims/Jenkins

docker ps

Edit inbound rule, open 8080 port no.

Getting started Jenkin.

8
9
Create new item.

Add webhooks in our GitHub repo.

Configuration changes in our Project.

10
Console Output.

Build Stages.

11
Update of nodejs with nodejs package

For development laptop


Install git bash for windows
Create folder nodeapp in any drive
Under folder open gitbash here
git inti
git config - - list
git cofig - - global user.name name
git config - -global user.email email
git config - - list
git intit
git remote add origin githubrepo
git pull origin master
ls
nano index.js

12
git add .
git commit -m “changecommit”
git status
git push origin master

13
Build Job
In Jenkin Server
New item
• Name – nodeappbuild
• Freestyle project
• Ok
• Git

14
• Paste gitrepo url
• Check branch
• Github hook trigger
• #create new webhook in Github repo settings
Build step
• Execute shell
• Echo “build Successfully”
• Save

15
Edit index.js
git add .
git commit -m “againcommit”
git push origin master

16
Manage jenkin
• Plugins
• Available plugins
• Nodejs
• Select
• Install
• Tool
• Nodejs installation
• Add nodejs
• Nodejs 18.0.0
• Name – mynode
• Save
Dashboard
• Nodeappbuild enter
• Configure
• Environment
• Provide node and npm bin/folder to PATH
• Select name
• Execute shell
Npm install

17
• Save

18
19
Git add .

Git commit -m “third commit”

Git push origin master

20
Test Job
• New item name - - nodeapptest
• Paster git repo
• Trigger – build after other project are built project name
• Build step – execute shell npm instal
./node_modules/mocha/bin/_mocha - - exit ./test/test.js
• Environment – provide node and npm bin/folder to PATH
• Edit some code and Push to Github test nodeapptest

21
22
Setup Live Server

23
24
25
Deploy Job
New item
Name - - nodeappdeploy
Freestyle project
Git - paste url
Trigger – build after another project are built
Environment - provide node and npm
build step - execute shell script on remote host using shell
command cd /nodejsapp
git pull origin master

26
npm install
pm2 restart index.js
build now
changed some code in Development laptop and Test pipeline

27
28
29
30
31
Docker NodeJS Jenkins

Create folder in our local laptop - - development laptop


git push All code to GitHub

sudo chmod 666 /var/run/docker.sock


docker run -d --name jenkins -v /home/ec2-user/jenkinsvolume:/var/jenkins_home -v
/var/run/docker.sock:/var/run/docker.sock -v /usr/bin/docker:/usr/bin/docker -p
8080:8080 jenkins/jenkins:lts

Dockernodebuild
freestyle project

Create Webhook in Github

Add git repo

Trigger - - github hook trigger

Manage Jenkins - - Available plugin - - docker pipeline and docker_build_step and docker Install

32
33
34
35
Dockernodetest

36
37
Live Server SetUp

38
Deploynodedeploy

39
40
41
Testing of Jenkins for docker NodeJS project

42
43
Jenkin installation on Amazon Linux

Steps –
sudo wget -O
/etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-
stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-
2023.key
sudo yum upgrade
sudo dnf install java-17-amazon-corretto -y
sudo yum install jenkins -y
sudo systemctl enable Jenkins
sudo systemctl start Jenkins
sudo systemctl status Jenkins
sudo cat /var/lib/Jenkins/secrete/initialAdminPassword
#Steps while disk space is minimum
df -h
sudo mount -o remount,size=2G /tmp
sudo nano /etc/fstab
tmpfs /tmp tmpfs defaults,size=2G,noatime,nosuid 0 0
sudo mount -o remount /tmp
df -h
sudo service Jenkins restart

44
sudo yum install git

45
46
47
Python hosting with Jenkins
#development laptop
mkdir pythonapp
git init
git add remote origin gitrepourl
git add .
git commit -m “message”
git push origin master
#check in GitHub code push or not

#Build job
Name – pythonappbuild
Add git repo
Trigger – github hook
Build step execute shell
python3 -m venv myenv
source myenv/bin/activate
pip install -r requirements.txt
build now

48
#Test Job
Name – pythonapptest
Freestyle project
Add git repo
Trigger – build after other project pythonappbuild
Build step execute shell
python3 -m venv myenv
source myenv/bin/activate
pip install -r requirements.txt
python3 -m unittest discover -s test

#live Server Setup


python3 -v
sudo yum install python3-pip python3-virtualenv
pip -v
sudo yum install git -y
git clone githubrepo
ls
cd pythonapp
ls
python3 -m venv myenv
source myenv/bin/activate
pip install -r requirements.txt

49
sudo yum install nginx
sudo service nginx start
sudo nano /etc/nginx/nginx.conf
location / {
proxy_pass http://locathost:5000;
}
sudo service nginx reload
gunicorn - - workers3 - - bind 0.0.0.0:5000 app:app&
#copy ip and test works or not

#Deploy job
Name – pythonappdeploy
Freestyle job
Add git repo
Trigger – build after other project are built pythonapptest
Build step – execute shell using ssh
cd pythonapp
git pull origin master
pip install -r requirements.txt
killall gunicorn
gunicorn --workers 3 --bind 0.0.0.0:5000 app:app&
build now

#Create changes in development laptop and Test hole Jenkins


project.

50
51
52
53
54
55
56
57
58
59
CICD pipeline With Nodejs
Jenkins Pipeline is a suite of plugins that support implementing and
integrating continuous delivery (CD) pipelines into Jenkins. It allows
defining complex build, test, and deployment processes as code.

Types of Pipelines in Jenkins


1. Declarative Pipeline – Uses a predefined structure and syntax.
2. Scripted Pipeline – Uses Groovy scripting for flexibility.

NodeJS with Pipeline:


→ New item
→ Name: nodejswithpipeline
→ Select pipeline
→ Write description
→ Add git link under git section
→ Github hook trigger
→ Pipeline script
→ Hello world
→ Build now
→ Write pipeline script for NodeJS
→ Pipeline syntax sample step checkout: check out from version
control
→ Configure node by in Tool
→ Establish Live server and SSH agent from deploy stage.

60
61
62
63
64
65
66
67
#Again Testing.

68

You might also like