Monday, February 28, 2022

Jenkins- CICD Pipeline


Github with Jenkins

1. Create a freestyle project in jenkins (Githubjob)

2. Configure GitHub url in the property  GithubProject-->URL

3.Provide same Github url In Source Code Management --> git  --->

4. Save this project 

5. Build the project which will provide you the workspace folder.

Maven Integration with Githubjob

1. Create a freestyle project in jenkins (Mavenjob)

2. Configure this job by using the Build -> ExecuteShell and use below command

        cd /var/lib/jenkins/workspace/Githubjob

        sudo mvn clean package

3. Goto Github project and in Post Build Action select MavenJob

4. Build Github project it should automatically trigger MavenJob 

Maven Integration Plugin

In the above example, you have created 2 jobs (Github,Maven) but with the help of Maven Integration plugin, we can create a single job that can perform the same operations as these 2 jobs are doing.

1. Goto Manage Jenkins---> Add Plugin -->Available-->Maven Integration

  then install without restart

2. Goto Manage Jenkins---> Global Tool Configuration--> Maven and provide some valid name like mvn1 and save the settings.

3. Create Maven Project with Project type Maven Project ( new project type is added after adding the Maven Integration Plugin)

4. Configure github url in the property  GithubProject-->URL

5.Provide same Github url In Source Code Management --> git  --->

6. Provide Maven Build Goal :- clean package

7. Save it and Build the project

8. On-Command terminal goto the workspace folder and there you will find the target folder with jar file.

Docker job to Create a docker image and container

In the repository, there is a docker file that has the code to create a docker image as per the maven jar file.

1. Create a freestyle docker project.

2. Goto Build option and change directory to Maven project folder

  • cd /var/lib/jenkins/workspace/Maven-Project
  • sudo cp target/myproj-1.0-SNAPSHOT.jar .
  • sudo docker build . -t mvnimg:$BUILD_NUMBER
  • sudo docker container run -it -d mvnimg:$BUILD_NUMBER

3. save this project

4. Goto Maven Project and in Post Build Action select docker job project.

5. Run Maven Project it will execute the docker job once it is finished successfully.

6. Check-in Jenkins server, docker images, and docker container ls --all

7. Image and container should be created.

Configure Email Notification.

1. Manage Jenkins---> Configure System---> At the bottom select the option Email Notification and provide SMTP server, user name , password details..

Test Dummy Job

In post-build action of Test job add Email notification detail.

Create a dummy freestyle project and make it as a part of post build action of docker project

Github Webhook.

1. Goto github project and select Settings--->Webhook---> Add Webhook ---> PayLoad URL--> provide jenkins url like   and click on Add Webhook

2. Goto Maven Project and select configure Build Triggers --> GitHub hook trigger for GITScm polling

Create CICD Pipeline

1. Manage Jenkins --> Manage Plugins---> Build Pipeline--> Install without restart

2. In the Dashboard click on + and select Build Pipeline project

3. Select Initial job as Maven Project

4. Update a code in github and it should automatically trigger complete CICD pipeline.


Post a Comment