Monday, February 18, 2019

How to Configure webhooks in GitHub | How to trigger Jenkins jobs instantly? - GitHub Webhooks Example

Webhooks allows developers to triggers jobs in CI server (such as Jenkins) for every code changes.


Make sure you install GitHub integration plug-in in Jenkins

1. Go to Jenkins, Create a job. If you already have a existing job, click on configure. Go to build triggers section and choose the below option - GitHub hook trigger for GitScm pooling.

2. Now go to GitHub, choose your repository. Click on settings, Webhooks.

3. Click on Add web hook.

4. Go Jenkins, copy the URL from the browser--> http://jenkins_public_dns_name:8080

5. Now enter Jenkins URL, select just push event, click on active. Click on Add webhook
6. Now go and make some code changes in your repo in GitHub

7. If you look in Jenkins, you will see job is getting triggered immediately.

You can watch these steps as video on my YouTube channel as well:

Saturday, February 16, 2019

Create Freestyle job in Jenkins | How to create build job in Jenkins to automate build and deployment

Jenkins is popular open source Continuous integration tool. It was written entirely in Java. Jenkins is a self-contained automation server used for automating builds, tests and deployment.

See below the steps for configuring Jenkins to automate the build and deployment for the project we already set up in Bitbucket or Git Hub.
pre-requisites:(please do this first before you start)

1. Make sure you configure maven installation under Jenkins-->manage Jenkins-> Global Tool Configuration. under maven installation. enter Maven3 as name, enter path of maven installation --> /usr/share/maven and uncheck install automatically option.

2. Also install SonarQube scanner,  deploy to container Jacoco plugins under Jenkins --> Manage Jenkins --> Manage plug-ins

Click on Available, type Sonarqube, select SonarQube scanner. Click on Install without restart.


Deploy to container


Click on without restart.

3. Generate Personal Access Token(PSA) if you are using GitHub. Click here to learn how to generate that in GitHub and you can use your token as password.

steps to automate MyWebApp project in Jenkins:

1. Login to Jenkins. Click on New item.

2. Enter an item name --> select Free style project.
enter name as myFirstAutomateJob. click OK.
3. under source code mgmt, click git. enter Bitbucket URL or GitHub URL
Click on your repo, Copy the url from the browser. Paste the url as Repository URL below.

under credentials --> click Add- > select Jenkins -->  enter your GitHub username and Personal Access Token as password. DO NOT use Git Hub password as it is removed from August 13, 2021. Click to here to learn how to generate Personal Access Token. Add description as my SCM credentials.

Enter main as branch specifier or which ever branch you want to check out.

4. select that from drop down.
5. under build trigger click on poll scm, enter this value to check

for every 2 mins --> H/02 * * * *

6. Build --> Add build step --> invoke top level maven targets -->

select Maven3 from drop down and goal as clean install

7. Click on advanced, enter the path of POM file as --> MyWebApp/pom.xml

8. click on Add post build action, select Record Jacoco Code coverage report
9. click on Add post build action, select deploy war/ear to container.

      for WAR/EAR files enter as 

in WAR/EAR files, leave context path empty

   10. click on Add container , select Tomcat 9.x

   11. click on add credentials, enter tomcat as user name and password as password.
      select it from drop down.

13. tomcat url should be --> http://your_public_dns_name:8080

click Apply, click Save
click on build now..It should build.
if there is any error, please check the console output. Most of the common error would be checking the path of Maven installation, valid credentials for GitHub or Tomcat. Also make sure you install the plug-ins.

After successful deployment, please make sure you check the output in Tomcat by going to browser and enter below URL

You should see Hello World!!!

This is how you automate the builds and deployments using Jenkins and migrate applications to AWS.

You can watch the video of this lab here:


Friday, February 15, 2019

How to setup Jenkins on Redhat Enterprise Linux? Jenkins installation on RedHat Linux - Install Jenkins on RedHat Linux

Here are the steps for installing Jenkins on RedHat Enterprise Linux.

You need to setup Java first.

Make sure you have installed wget.

sudo yum install wget -y

Java Installation

Download Java from Oracle site.

sudo wget --no-check-certificate --no-cookies --header 'Cookie: oraclelicense=accept-securebackup-cookie' ''

Install from RPM
sudo  rpm -i jdk-8u141-linux-x64.rpm

Add Jenkins repository to yum repository

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

Install Jenkins
sudo yum install jenkins -y

Start Jenkins
sudo service jenkins start
sudo service jenkins status

You should see below message. that confirms that Jenkins is up and running.
 jenkins.service - LSB: Jenkins Automation Server
   Loaded: loaded (/etc/rc.d/init.d/jenkins; bad; vendor preset: disabled)
   Active: active (running) since Fri 2018-06-08 19:41:28 UTC; 4min 34s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 15404 ExecStart=/etc/rc.d/init.d/jenkins start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/jenkins.service

Get Jenkins Admin Password
sudo cat /var/lib/jenkins/secrets/initialAdminPassword

Copy the output of the above command.
Now go to browser and access the Jenkins page.


Your page will look something like this. Now paste the password into the below Administrator password text box.
Press Continue..Click on install suggested plug-ins..

That's it Jenkins is successfully installed..

Thursday, February 14, 2019

How to integrate SonarQube and Jenkins - Jenkins SonarQube integration

Here below are the steps for integrating SonarQube with Jenkins:
Pre-requisites: Make sure SonarQube is up and running and do the below steps:
Make sure Sonarqube plug-in installed in Jenkins

1. You need to login to SonarQube using admin/admin and click on administration, security, users, click on Tokens, under generate token. Give some value for token name and click on generate. Copy the token.

2. After installing SonarQube successfully, login to Jenkins. Manage Jenkins --> Configure System --> SonarQube installation

Enter name, URL as http://localhost:9000, paste the token you copied from step #1
3. Click on Enable injection of Sonarqube server configuration.
4. Save.
5. Click on your existing free style job, click on configure. click on prepare Sonarqube scanner  environment.

6. enter maven goal as clean install sonar:sonar

7. click on save and build the job.

You will see that Jenkins will integrate with Sonarqube which does code analysis of your project.
Login to SonarQube, click on Projects to see the project dash board.

terraform create s3 bucket example - How to create S3 bucket using Terraform

Terraform is an infrastructure orchestration tool for creating web services in AWS automatically. You can use Terraform for provisioning S3 bucket in AWS.

sudo vi

resource "aws_s3_bucket" "mybucket" {
  bucket = "my-tf-test-bucket"
  acl    = "public-read"
  website {
    index_document = "hello.html"
   routing_rules = <<EOF
    "Condition": {
        "KeyPrefixEquals": "docs/"
    "Redirect": {
        "ReplaceKeyPrefixWith": "documents/"

  tags= {
    Name        = "My bucket"
    Environment = "Dev"

Once you create the above file, execute terraform plan and then terraform apply to create S3 bucket in AWS.

Terraform destroy single resource or all resources | How to destroy a specific resource using Terraform in AWS cloud

If you would like to destroy all the resources you had created using Terraform, all you have to do is perform the below command:
terraform destroy
and type yes to confirm you want to all the resources.

The above command will destroy all the resources. 
But let's say you would like to destroy only a specific resource you have created using Terraform. You can do it by passing a an argument in terraform destroy command. if you would like to delete EC2 instance, you can mention like below:

Destroy specific resources

Get all the resources created by Terraform
terraform state list

terraform destroy -target aws_instance.myInstanceName

if you would like to delete a security group, you can mention like below:
terraform destroy -target aws_security_group.security_group_name
Please watch in my YouTube channel on how to do the above steps:

Tuesday, February 12, 2019

Jenkins setup - Install Java, Jenkins, Maven, Tomcat on Ubuntu EC2 - How to install Java, Jenkins, Maven, Tomcat on Ubuntu EC2

Please follow steps to install Java, Jenkins, Maven, Tomcat on Ubuntu EC2. Jenkins is a java based application, so you need to install Java first. 

Java Setup on Ubuntu

sudo apt-get update

Install Java 11

sudo apt-get install default-jdk -y

Now lets do Jenkins installation

Jenkins Setup

Add Repository key to the system

wget -q -O - | sudo apt-key add -
Append debian package repo address to the system

echo deb binary/ | sudo tee /etc/apt/sources.list.d/jenkins.list

sudo apt-get update
Install Jenkins
sudo apt-get install jenkins -y

The above screenshot should confirm that Jenkins is successfully installed.

Access Jenkins in web browser

Now Go to AWS console.
  Click on EC2, click on running instances link. Select the checkbox of EC2 you are installing Java and Jenkins.

  Click on Action.
  Copy the value from step 4 that says --> Connect to your instance using its Public DNS

Now go to browser. enter public dns name or public IP address with port no 8080.This is how to select public DNS name:

Unlock Jenkins
You may get screen, enter the below command in Git bash( Ubuntu console)
Get the password from the below file

sudo cat /var/lib/jenkins/secrets/initialAdminPassword

Copy the password and paste in the browser

Click on install suggested plug-ins.
Also create user name and password.
enter everything as admin. at least user name as admin password as admin
Click on Save and Finish. Click on Start to Use.

Maven is a build tool used for building Java applications. Please click here to learn more about Maven. You can install Maven by executing below command:

sudo apt install maven -y

you can type mvn --version
you should see the below output.

Tomcat Installation

Tomcat is a web server or web container where java web application can be deployed by developers. You can learn more about by clicking this URL.  Tomcat can be installed by executing below commands:

sudo apt-get update
sudo apt-get install tomcat8 -y

sudo apt-get install tomcat8-docs tomcat8-examples tomcat8-admin -y

sudo cp -r /usr/share/tomcat8-admin/* /var/lib/tomcat8/webapps/ -v

Click on this link to know how to make changes using Vi editor.

Change port no from 8080 to 8090
Tomcat default port is also 8080, since we have already used 8080 for Jenkins, we need to change from 8080 to 8090. You can change by modifying server.xml

sudo vi /var/lib/tomcat8/conf/server.xml

you need to scroll down by clicking down arrow button in this file change the port no from 8080 to 8090 at line starting with <Connector port="8080" protocol="HTTP/1.1"

setup an user in tomcat 

sudo vi /var/lib/tomcat8/conf/tomcat-users.xml

Scroll down all the way to the end of the file,
Add the below lines in second last line above (above </tomcat-users>)
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<user username="tomcat" password="password" roles="manager-gui,manager-script"/>

Add more memory to JVM
sudo vi /etc/default/tomcat8

Look for the line starting JAVA_OPTS and comment that line by adding #.
Add the below line:
JAVA_OPTS=" -Djava.awt.headless=true -Xmx512m -XX:MaxPermSize=512m -XX:+UseConcMarkSweepGC"

sudo systemctl restart tomcat8

sudo systemctl status tomcat8

you may get message that says tomcat is active running.
press q for quitting from that window. Now go to browser, copy public DNS.

You should see a page that says.
It works!!!!

That's it. You have setup both Jenkins and Tomcat successfully!!

Please watch here for live demo:

Install Helm 3 Linux - Setup Helm 3 on Linux | Install Helm 3 on Ubuntu | Setup Helm 3 on Linux | Setup Helm 3 on Ubuntu

What is Helm and How to install Helm  version  3? Helm is a package manager for Kubernetes. Helm is the K8s equivalent of yum or apt. I t a...