DevOps Classroomnotes 26/Feb/2023

Installing Maven

  • Maven requires Java to be installed.
  • Java:
    • Distributions:
      • OpenJDK
      • Oracle JDK
      • IBM JDK
      • Amazon Corretto JDK
    • Versions:
      • 8
      • 11
      • 17
      • 19
  • Environmental Variables:

    • PATH
    • JAVA_HOME
    • M2_HOME
  • JAVA Installation
# OpenJDK 8
sudo apt update
sudo apt install openjdk-8-jdk -y
java -version
  • Maven Installation
sudo apt update
sudo apt install maven -y
mvn --version

Preview
* Building a sample application using maven Refer Here for game of life code
* This project requires jdk 8
* To
* compile the code: mvn compile
* run the automated tests: mvn test
* create the package: mvn package
* Lets try to build a project spring petclinic Refer Here. This project requires JAVA 17
* When we were compiling, testing and packaging maven is downloading lot of stuff what is that?
Preview
* Maven will download all the necessary dependencies to compile/package/test from a maven central repository Refer Here and it downloads to M2_HOME which is by default <HOME-DIR>/.m2 which is referred as local repository.

  • Maven Lifecycle Phases
    • compile: Will create .class files
    • test: will run unit tests
    • package: will create package (jar/war)
    • install: will copy the project which you have build to the local repository. Along with jar/war files a pom also gets copied

Jenkins

  • Jenkins is an open source CI/CD Engine.
  • Jenkins:
    • Using Package managers on Linux
    • Docker
    • Windows
    • WAR
  • Lets install Jenkins Refer Here
  • For installing in ubuntu Refer Here
  • Lets install LTS (Long Term Support Version)
sudo apt-get update
sudo apt-get install openjdk-17-jdk -y
curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo tee \
  /usr/share/keyrings/jenkins-keyring.asc > /dev/null
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
  https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
  /etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update
sudo apt-get install  jenkins -y
  • After installing jenkins a user jenkins got created with
    • /var/lib/jenkins as Home directory
    • /bin/bash as default shell
  • Now access jenkins using http://<publicip>:8080
  • copy the inital secret and click on continue
    Preview
    Preview
    Preview
  • Create an admin user
    Preview
    Preview
    Preview
    Preview

First Project to display some system information

  • Lets create a Jenkins project which displays
    • username
    • current working directory
    • all the environmental variables
  • Lets start by create a Jenkins project (Freestyle)
    Preview
  • Now navigate to build steps
    Preview
    Preview
    Preview
    Preview
    Preview
    Preview
  • Now change the invoke shell steps to something as shown below
    Preview
  • Build the jenkins job
    Preview
    Preview

Create a Jenkins Project to build spring petclinic

  • Manual steps
git clone https://github.com/spring-projects/spring-petclinic.git
cd spring-petclinic
mvn package
  • Create a Jenkins job with name spc and in build steps invoke shell and execute the following
git clone https://github.com/spring-projects/spring-petclinic.git
cd spring-petclinic
mvn package

Preview
Preview
* Install maven and rerun the same job
Preview

Exercise

  • Install Jenkins on a ubuntu vm
  • Try to build game of life using jenkins free style project mvn package
  • Refer Here for the the project

Jenkins Projects

  • Jenkins has 3 project types (majorly)
    • Free Style: These projects are UI Based.
    • Scripted Pipeline
    • Declarative Pipeline

Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Animated Social Media Icons by Acurax Wordpress Development Company

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube