Release Management: Setup Jenkins Continuous Integration Pipeline From GIT to Tomcat
- Jenkins is Working
- Tomcat is working
- Maven is installed on Jenkins Machine
- You have a working Maven Project that you are able to build and deploy
- Git is installed on Jenkins Machine
- You have a working project on GitHub
- You are able to down load your project from github
- You are able to send changes to github from your machine
- You are able to build the project which is on Github
- You are able to deploy the project (built from Code in Git) to Tomcat
- Below Plugins are installed in Jenkins
- Deploy to container Plugin
- Clone Workspace SCM Plug-in
- Git plugin
- Build Pipeline Plugin
Build a First Web project using maven in Jenkins
We will use a Project that we have used and tested earlier
- Type = Maven Project
- Name = TESTING3
- Source Code = NONE
- Build Triggers = Nothing should be selected
- BUILD Root POM = /home/u_jenkins/TESTING3/my-first-webapp/pom.xml
- Goals = clean package
- [[ SAVE ]]
- Once Created Use the [[Build Now]] on the left hand side.
- Once Build is running use the [[Console Output]] on the left hand side to see the output
Validate the console output as below:
Setup Tomcat Security so that we can deploy from Jenkins
- $ vi ~/TOMCAT/conf/tomcat-users.xml
- $ cat ~/TOMCAT/conf/tomcat-users.xml
- <?xml version=’1.0′ encoding=’utf-8′?>
- <user username=”deployer” password=”secret-deployer” roles=”manager-script”/>
- $ ~/TOMCAT/bin/catalina.sh stop
- $ ~/TOMCAT/bin/catalina.sh start
- Tomcat started.
Build a First Web project using maven and GIT and Deploy to Tomcat in Jenkins
In this section we will see how to Build a Pipeline from GIT to Tomcat:: Putting it all together
- DEMO_PULL_FROM_GIT ( Freestyle Project)
- Git -> Repository URL = https://github.com/pathikpaul/learngit.git
- The SSH agent that we started earlier should be running
- Post-build Actions = Archive for Clone Workspace SCM
- DEMO_BUILD_DEPLOY (Maven Project)
- Source Code Management -> Clone Workspace -> DEMO_PULL_FROM_GIT
- Build Triggers-> Build after other projects are built (DEMO_PULL_FROM_GIT)
- BUILD Root POM = pom.xml
- Goals = clean package
- Post-build actions ->
Follow the screen shots below if you need more details
Now run the first job in the pipeline Pipeline DEMO_PULL_FROM_GIT , it should kick off the next job, they should all be success.
Use the “Build Now” and “Console Output” links.
Now we will set up the pipeline view. ( use the “+” which is next to All as per the screen shot below)
View Name = Demo
Build Pipleline View
Use “DEMO_PULL_FROM_GIT” as the fist project.
Build a Pipeline which is automatically triggered when there is change in Source
We will make a change to trigger this pipeline whenever there is a change in GIT.
We will update the first project and setup a polling frequency of every 5 minutes for testing purposes.
We can look at the “Git Polling Log” to validate that all is working well. Git should be pulling from the source control repository every 5 minutes.
Now we will change the Source Code and push changes to Github
Let us use a brand new directory
- $ mkdir –p /home/u_jenkins/TESTING
- $ cd /home/u_jenkins/TESTING
- $ git clone firstname.lastname@example.org:pathikpaul/learngit.git
- Initialized empty Git repository in /home/u_jenkins/TESTING/learngit/.git/
- remote: Counting objects: ….
- remote: Total ….
- Receiving objects: 100% (….), done.
- $ cd /home/u_jenkins/TESTING/learngit
- $ vi ./src/main/webapp/index.jsp
- $ cat ./src/main/webapp/index.jsp
- <h2>Hello World ! This line added after Jenkins pipeline is setup </h2>
- $ git add ./src/main/webapp/index.jsp
- $ git commit -m “changed index.jsp after pipeline is built”
- [master 78e8b9e] changed index.jsp after pipeline is built
- 1 files changed, 1 insertions(+), 1 deletions(-)
- $ git push
- Counting objects: 11, done.
- Compressing objects: 100% (4/4), done.
- Writing objects: 100% (6/6), 527 bytes, done.
- Total 6 (delta 1), reused 0 (delta 0)
- To email@example.com:pathikpaul/learngit.git
- .78e8b9e master -> master
Pipeline gets run automatically without any human intervention. It does the build and does the deployment to our tomcat.
Updated Application is deployed
Author: Pathik Paul