January 2020

Monday, January 27, 2020

Integrating Jenkins with Slack and Email Notification



Continuous Integration is a process in which all the development work will be integration as early as possible. The resulting artefacts are automatically created and tested. In this blog will help you the continues integration Jenkins with Slack and Email Notification, In order to notify developer each and every build on the slack channel and also if any build failed you will be notified in your mail.

Jenkins CI With Slack And Email Notification
Jenkins CI With Slack And Email Notification

1. Introduction


    Jenkins is an open-source continuous integration software tool which is written in Java for testing & reporting the isolated changes in larger code basis in real-time project. This is the software that enable developer to find the defects and solve it rapidly via automation testing. 

2. Create Slack Account

      Well Slack is charting software. Slack has provides a hooks, which helps to provide communication to your team members. Here are integrating Jenkins, so it can sends all the latest build notification into your slack Channel. So, If you haven't created your slack account till now, You can visit the below link - 

https://slack.com/signin?redir=/apps/manage

Or Channel Administrator - > Manage Apps - > Create Incoming webhooks


Once you have created a account, Please go Slack -> Administrator - > ManageApps

Slack Manage Apps
Slack Manage Apps


Search for Incoming WebHooks - 

Search For Incoming WebHooks
Search For Incoming WebHooks

Once you have done that. You will get the Below Screen - 

Incoming WebHooks
Incoming WebHooks

Once you have done that, please click on Add to Slack, You will get the below screen - 

Select-Channel-Name
Select Channel Name

Click on Add Incoming WebHook integration. You should get a slack webhook URL. Looks 

https://hooks.slack.com/services/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

You can also test the things from CURL Command - 

curl -X POST --data-urlencode "payload={\"channel\": \"#codeztech-jenkins\", \"username\": \"webhookbot\", \"text\": \"This is posted to #codeztech-jenkins and comes from a bot named webhookbot.\", \"icon_emoji\": \":ghost:\"}" https://hooks.slack.com/services/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

Details please check the below Screen Shot - 

Slack Webhook URL
Slack Webhook URL

3. Configure Slack Notification Plugin in Jenkins


   Make sure You have installed Slack Notification Plugin from Jenkins Manage Plugin. Please install the Lower version such as 2.20. If you don't know where to install version 2.2o plugin, please visit and download from the below link - 


Once you have done that, go to Manage Jenkins -> Upload This Plugin and Restart your Jenkins. I have made a complete video on that, I am attaching it in the below this blog. Feel free to comment on my Youtube channel or this blog, if you have any issue. 

Once you have done that, Go to Manage Jenkins - > Configure System. 

Your Base URL  will be always - https://hooks.slack.com/services/ 
Team SubDomain - Will be Your  - Channel Name -- You will get it from your URL path like 

Slack - Incoming WebHook Team Sub Domain
Slack - Incoming WebHook Team Sub Domain

Add the credential and provide your channel name adding to # . Like where you are planing to send all the build notification. Click on Test Connection in order to whether the current setup is working properly or not.

Configure Slack On Jenkins
Configure Slack On Jenkins

4. Configure Email Notification in Jenkins


     In order to configure email notification in Jenkins We need to follow the below steps - 

SMTP Server - smtp.gmail.com
Default Email - @gmail.com

Check on the SMTP Authentication
Username - youremailId
Password -

Dont put your gmail password. Google won't allow that. what you have to Dont

Step 1 - Login to your gmail -> Go to manage your account
Step 2 - Click on the security tab -> Singing in to Google
Step 3 - Click on App password -> Select the Device you want to generate the password
Step 4 - Generate password

After that copy password and paste it -

Check on the SMTP Authentication
Username - youremailId
Password -
Check on ssl
SMTP Port - 465
Reply to Address - your other gmail youremailId
Finally click on test


Details please check the below Screen Shot - 

Configure-Email-Notication-On-Jenkins
Configure Email Notification On Jenkins

More Details please check my below videos - 


Sunday, January 26, 2020

Jenkins: How to Create Builds with the Jenkins Freestyle Project



A Jenkins project is a repeatable build which contains steps and post build actions. The type of action you can perform beginning of build step or post build action. There are many standard plugin are available with in a Jenkins free style project to help you to overcome your problem.

Jenkins-create-build-free-style-project.png
Jenkins create & build free style project
  


1. Free Style Project in Jenkins

 A Jenkins project is contains steps and post build actions. The type of action we can perform in order to build step, post-build action or Jenkins pipeline. There are tons of standard plugin available in Jenkins to overcome our problem.  

2. Jenkins -  Creating Free Style build Job

  For Creating the Jenkins free style job, we have to login to our Jenkins Dashboard. If it is hosted locally please visit http://localhost:8080 If you hosted some the URL visit over there. 

Step - 1

    Click on the new Item, top left corner of your dashboard - 

Jenkins NewItem
Jenkins NewItem
Step - 2

Enter the name of the item, choose freestyle project and click on ok.

Freestyle Project
Freestyle Project
Step - 3

Enter the details of the project you want to set. 

Jenkins Project Details
Jenkins Project Details

Step - 4

Under the source code management please enter your repo URL. In order to clone your repository and run it. Your url can be - https://github.com/kriru/firstJava.git

Jenkins Setup Git Project
Jenkins Setup Git Project

Step - 5

Next click on Add build step - > Execute Windows batch command and add the command you want to execute, Our case -  

javac HelloWorld.java
java HelloWorld

Jenkins Build Windows Batch Command
Jenkins Build Windows Batch Command

Step - 6

 After that click on apply & Save - > Build now, in order to check whether the build is successful or not. 

Jenkins Build Now
Jenkins Build Now


Jenkins Build Successful
Jenkins Build Successful


Step - 7

    If you want to explore it more you can click on console output to see the details result. 

Jenkins console output
Jenkins console output



Congratulations,  we have executed our HelloWorld program from Jenkins. 


More Details you can see my below video link - 



Jenkins : How to download and install Jenkins



Jenkins is an open source automation server. which help to automate the non human part of software development process with continuous integration, continuous delivery and continuous deployment. It a server based system, which runs servlet container such as apache tomcat. 

Jenkins
Jenkins - Installation of Jenkins

1. Overview

            
        Jenkins is an open-source automation tool developed by sun microsystem and written in Java. Initial released date was 2nd february 2011. Jenkins offers continuous integration with continuous delivery and continuous deployment pipeline. Jenkins setup is also breeze due to java based construction. It is ready to play right out of the box & works well with windows, Mac OS X, Linux and Ubuntu.


In this tutorial we will walk you through steps of installing Jenkins on a Linux operating system. 

2. Hardware Requirements

  • We need minimum 256 mb of RAM in order to install Jenkins on computer.
  • 1 GB hard drive space

3. Software Requirements

              Since Jenkins developed by sun microsystem and written in Java. We have to make sure about that Java is Installed in our system. In order to see whether Java is installed or not, we can say from terminal or command prompt - 

java -version

openjdk version "12.0.1" 2019-04-16
OpenJDK Runtime Environment (build 12.0.1+12)
OpenJDK 64-Bit Server VM



If it is not yet installed then - 


# install java 1.8 on Amazon Linux
sudo yum update -y
sudo yum install -y java-1.8.0-openjdk-devel
sudo alternatives --config java



4. Install Jenkins on Linux Operating System

        For installation of Jenkins on linux operating system please follow up the below steps - 


# install Jenkins on Amazon Linux

sudo wget -O /etc/yum.repos.d/jenkins.repo

http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo sudo rpm --import
http://pkg.jenkins-ci.org/redhat-stable/jenkins-ci.org.key
sudo yum install jenkins


If you are installing Jenkins in Amazon Cloud server, while connecting to EC2 server make sure you have followed the below steps, or else you won't be able to connect -

# ssh into EC2 instance
ls -lah /path/jenkins-key.pem
chmod 400 /path/jenkins-key.pem
ssh -i /path/jenkins-key.pem
ec2-user@ec2-123-456-78-9.compute-1.amazonaws.com

Once your installation is done please start and enable your Jenkins service by saying - 

# start Jenkins at boot time
sudo systemctl start jenkins.service
sudo systemctl enable jenkins.service

If you want to restart your Jenkins please follow below steps - 

#Restart Jenkins
sudo /etc/init.d/jenkins restart

Make sure you have installed git if you are dealing with cloning repository from bitbucket or Github or any other platform - 

# install git
sudo yum install git


5. Install Jenkins on RPM Distros Operating System

      For installation of Jenkins on rpm distros please follow up the below steps - 

# Add yum repo and install Jenkins
sudo wget -O /etc/yum.repos.d/jenkins.repo
http://pkg.jenkins-ci.org/redhat-stable/
jenkins.repo
sudo rpm --import
http://pkg.jenkins-ci.org/
redhat-stable/jenkins-ci.org.key
sudo yum install jenkins

Once your installation is done please start and enable your Jenkins service by saying - 

# Start Jenkins at boot time
sudo systemctl start jenkins.service
sudo systemctl enable jenkins.service

If you want to restart your Jenkins please follow below steps - 

#Restart Jenkins
sudo /etc/init.d/jenkins restart

6. Install Jenkins on Ubuntu Operating System

        For installation of Jenkins on ubuntu please followup the below steps - 


# Add PPA repo for Jenkins stable LTS
wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key
| sudo apt-key add -
sudo sh -c "echo deb http://pkg.jenkins.io/debian-stable binary/ >
/etc/apt/sources.list.d
/jenkins.list"
sudo apt-get update

# Install Jenkins
sudo apt-get install jenkins

Once your installation is done please start and enable your Jenkins service by saying - 

# Start Jenkins at boot time
sudo systemctl start jenkins.service
sudo systemctl enable jenkins.service

If you want to restart your Jenkins please follow below steps - 

#Restart Jenkins
sudo /etc/init.d/jenkins restart

7. Install Jenkins with Docker

          For installation of Jenkins with docker please follow the below steps - 

# Pull official Docker image for Jenkins LTS
docker pull jenkins/jenkins:lts

# Start Docker container
docker run -p 8080:8080 -p
50000:50000 -v
jenkins_home:/var/jenkins jenkins/jenkins:lts

# Start Docker container in detached mode
docker run -p 8080:8080 -p 50000:50000 -v
jenkins_home:/var/jenkins -d
jenkins/jenkins:lts


8. Unlock Jenkins 


Once your installation is done you can type from your browser - 

If you have installed Jenkins in your local system then - 

localhost:8080

If you have installed Jenkins in your server then - 

Your_Server_Public_Ip:8080

You will get the below screen - 

Unlock Jenkins
Unlock Jenkins
Order to get the password from you command prompt do - 

cat the_path_is_provided_on_screen_like
cat
/var/lib/jenkins/secretes/initialAdminPassword


Please copy the password from the terminal and click on continue, you will see - 

Customize Jenkins
Customize Jenkins

Click on Install Suggested Plugins, then - 

jenkins getting started
Jenkins Getting Started

Once your installation is done, you will be asking for reset password - 

Reset your username and Password
Reset your username and password
Click on save and continue, 

Jenkins Instance Configuration
Jenkins Instance Configuration
Click on save and continue and congratulations, we have successfully installed Jenkins Server. Hit start using Jenkins - 

Jenkins is ready
Jenkins is ready

Then you will see the below screen - 

Welcome to Jenkins - Start Create New Job
Welcome to Jenkins - Start Create New Job


More details please visit official Documentation - https://jenkins.io
More details please visit my youtube video - 









Sunday, January 5, 2020

Amazon EC2 Tutorial : Hosting Mean Stack Application



Amazon EC2 is one of the most used and most basic services in Amazons so it makes sense to start with EC2 when you are new to AWS. But the first question is that what is EC2 in AWS ?


AMAZON EC2 HOSTING MEAN STACK APPLICATION
AMAZON EC2 HOSTING MEAN STACK APPLICATION


1. What is EC2 in AWS ?


Well to be very simple, 


  1. It's basically virtual machine which includes CPU, RAM, ROM e.t.c
  2. It also allows to choose different platform ( like windows, linux, ubuntu e.t.c ) while you are launching virtual machine in cloud. 
  3. The Virtual machine we called it as an instance, you can easily start, stop or terminate your instance.


2. AWS EC2 Mean Stack Application Screens?


I am sharing few screens about out Mean Stack Applications that we are going to host it in AWS EC2. 

Insert - 

Mean Stack Crud Application Insert
Mean Stack CRUD Application Insert

Update -

Mean Stack Crud Application Update
Mean Stack CRUD Application Update

Delete -

Mean Stack Crud Application Delete
Mean Stack CRUD Application Delete

3. Architecture of the Mean Stack Application

    In the below diagram, this is the architecture of our mean stack application that we are going to setting up in 2 AWS instance. In the FrontEnd Part I am using Angular 6, and

MEAN STACK APPLICATION ARCHITECTURE
MEAN STACK APPLICATION ARCHITECTURE

whatever user interaction got happened like create, read, write and delete it's happening from Node JS. So Node Js is act as a mediator which helps to talk to my database mongo DB and get back the data to frontend. So we will be going to use 2 instance 1 for frontend and 1 for backend.

Mean Stack FrontEnd Project Link - 

Mean Stack BackEnd Project Link -

If you want to learn more about Mean Stack please visit my blog - 

My youtube - Mean Stack Tutorial



About the AMAZON EC2 Tutorial also you can see - 



2. Installation of MongoDB into AWS EC2 Instance

First if you have not registered in AWS please register first. Then launch an UBUNTU instance. Download the pem key. Open your terminal - 

ssh -i yourkey.pem ubuntu@your_ec2_public_ip

Once you have logged in then follow the below process,

For Installation of MongoDB please visit the below link - 



More details -

You can also see my below videos - 


3. AWS EC2 Hosting Mean Stack Application using PM2 - 


This is the other ubuntu Instance that we are launching it. First thing we need to install Node JS, Angular 6, NVM and PM2 in the AWS EC2 instance. Then we have to clone the code inside the EC2 instance. 

Install Node JS - 

sudo apt update
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - sudo apt-get install -y nodejs 

Install NVM for changing the Node JS version -


nvm ls-remote 

Install Angular 6 -
sudo npm install -g @angular/cli@6.0.7

Mean Stack FrontEnd Project Link - 

Mean Stack BackEnd Project Link -
git clone https://atique12@bitbucket.org/atique12/mongocrud_application_back_end.git 

Then edit the file - 

Mean Stack BackEnd Project - db.js and index.js - Instead of Localhost put first instance mongo DB EC2 Public ip to db.js and 2nd instance public ip to 2nd EC2 instance.

Mean Stack FrontEnd Project - Inside src/app/shared

vi person.services.ts

Change localhost to 2nd AWS EC@ public ip.

You can also Visit my youtube video for more details - 





Thank you guyz.

Please don't forgot to subscribe my youtube channel.