Shruti Kashyap
4 min readJan 6, 2022

--

Easy approach for implementing CI/CD using Jenkins-Part 2

Welcome back now let’s go to steps -:

TOOLS USED WITH VERSION-:

LINUX INSTANCE,GIT(1.8.3.1),Apache Maven(3.8.4),Jenkins (2.319.1),Apache Tomcat(9.0.56)

Steps -:

Set the git executable path and install required plugins in Jenkins -:

To set git executable path -Go to Jenkins->Global Tool Configuration->set the path to git executable(refer above image .)

To install plugin required plugin to integrate Jenkins with Maven and Tomcat :

Go to Jenkins->Dashboard->Manage Jenkins->Manage Plugins->Available(Refer to image below to get the names of required plugins)

Create a maven based project in Jenkins rather than freestyle one as it understands maven goals more easily and reduces configuration steps .

After giving description ,now give your local repository location ,it will start with file:////{local-repository}(refer to 2.1),so that Jenkins will understand it is the local one and also on the Linux instance to make your repository a git one .

Proceed with these git commands -:

git init →Used to make a existing repository as a git repository.

git add . →To add all the files to staging area which are ready for commit .

git commit -m “message” →It will commit all the files and message is necessary as it will help us to check logs by git log command in case of any conflicts.

git status →To check any files are there that is not committed but modified .

2.1

After setting up repository path ,go for build triggers which gives us the option to select how we want to initiate our build-:

Use cases (which to use when):

  1. Build whenever a SNAPSHOT dependency is built -This is convenient for automatically performing continuous integration. Jenkins will check the snapshot dependencies from the <dependency> element in the POM, as well as <plugin>s and <extension>s used in POMs.
  2. Trigger builds remotely-Enable this option if you would like to trigger new builds by accessing a special predefined URL (convenient for scripts).
  3. Build after other projects are built- Enable this when you want to run one project after building up other project .For ex-If you want to test the previous build is successful then you can try this option
  4. Build periodically- When you want to configure Jenkins as a cron job then you can use this option .For e.g. -to run backup every 15 minute we can write like this “*/15 * * * *”
  5. GitHub hook trigger for GITScm polling-When you want to trigger build through git hub hook trigger then you can enable this option
  6. POLL SCM-When you want Jenkins to scan entire workspace for git push occurrence ,it is quite expensive one but you can enable this .

Now to configure maven goals go for Pre-Steps options -:

Maven Goal Configuration

In this step we have to define root pom(an xml file needed by the maven to build the project) and also have to specify maven goal.

In the last step we have to configure post build actions to deploy war file to container -:

Post build actions

In the image above ,we are telling Jenkins to search for file which end with .war extension and give the context path name (part of the URL under which our application will be published in tomcat)

So now we are ready to apply the changes and access our application through the URL if the build is successful .URL will be the server name + port on which tomcat is running _context path .Check for the console output on Jenkins for detailed logs.

Hope it helps. All the best for your Dev-Ops journey

--

--