bookmark_borderCI/CD pipeline using Git, JenKins, and Maven

  1. Prerequisites
  2. Delete Java if Java version is not over 1.8 Install Java 1.8 version
  3. Confirm Java Version and set the java home
  4. Install Jenkins
  5. Check Jenkins status & start
  6. Open JenKins with port 8080
  7. Set Up JDK in Jenkins
  8. Run First Jenkins Job
  9. Configure Git plugIn on Jenkins
  10. Set Up Git in Jenkins
  11. Set Up Maven & Maven Home
  12. Configure Maven on Jenkins
  13. Create First Maven Job
  14. Build Maven project

Prerequisites

  1. EC2 Instance
    • With Internet Access
    • Security Group with Port 8080 open for internet
  2. Java v1.8.x

Delete Java if Java version is not over 1.8 Install Java

$ sudo su - 
$ java -version
java version "1.7.0_211"
$ yum remove java -1.7.0*

Install Java

$ yum install java-1.8*

Confirm Java Version and set the java home

$ find /usr/lib/jvm/java-1.8* | head -n 3
/usr/lib/jvm/java-1.8.0
/usr/lib/jvm/java-1.8.0-openjdk
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.252.b09-2.amzn2.0.1.x86_64

Open .bash_profile

$ vi ~/.bash_profile

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.252.b09-2.amzn2.0.1.x86_64
PATH=$PATH:$JAVA_HOME

export PATH

Install Jenkins

Jenkins Redhat Packages for CentOS/Fedora/Red Hat

$ sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
$ sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key

https://www.jenkins.io/download/

$ yum install jenkins

Check Jenkins status & start

$ service jenkins status
● jenkins.service - LSB: Jenkins Automation Server
   Loaded: loaded (/etc/rc.d/init.d/jenkins; bad; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:systemd-sysv-generator(8)
$ service jenkins start

Open JenKins with port 8080

Server_IP:8080

Default password

$ cat /var/lib/jenkins/secrets/initialAdminPassword
`auto_generated_password`

After rejoin Jenkins, you can change password in admin

Set Up JDK in Jenkins

  • JenKins Managment → Global Tool Configuration → JDK option (Add JDK)
NAME: JAVA_HOME
JAVA_HOME
  • Location of JAVA
$ echo $JAVA_HOME

Run First Jenkins Job

New Item → Enter an item name → Edit Description

For example)

Enter an item name: My_first_Job

Edit Description: My_first_Job

Source Code Management: None (Not yet Git Setting is finished)

Build:

  • Execute Windows batch command : If target system is windows
  • Execute shell: If target system is linux

Execute shell

Command

echo "Welcome to DevOps Project"

Save and try Build

Configure Git plugIn on Jenkins

  • Prerequisites: Jenkins Server

Change host name for Jenkins server (convention)

$ hostname jenkins 
$ sudo su -
$ yum install git -y

Now, you can add plugin

Manage Jenkins → Manage Plugins → Available

Search Github and add Plugin install without restart click

pull the code for GitHub to Jenkins

Set Up Git in Jenkins

JenKins Management → Global Tool Configuration → JDK option (Add JDK)

NAME: git
Path to Git executable: /usr/bin/git
  • In the latest version of Jenkins, we should provide the full path of git.

Please change “path to Git executable” to /usr/bin/git rather than just “git” as per the video.

Set Up Maven & Maven Home

  • Prerequisites: Jenkins Server

Download maven packages https://maven.apache.org/download.cgi

mkdir /opt/maven file Location

$ wget <http://mirror.apache-kr.org/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz>
$ tar -xvzf apache-maven-3.6.3-bin.tar.gz

Open .bash_profile

$ vi ~/.bash_profile

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.252.b09-2.amzn2.0.1.x86_64
M2_HOME=/opt/maven
M2=/opt/maven/bin
PATH=$PATH:$JAVA_HOME:$M2:$M2_HOME
export PATH

Check Maven Version

$ mvn --version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /opt/maven
Java version: 1.8.0_252, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.252.b09-2.amzn2.0.1.x86_64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.14.193-149.317.amzn2.x86_64", arch: "amd64", family: "unix"

Configure Maven on Jenkins

Manage Jenkins → Global Tool Configuration →Maven Option

NAME: maven_3.6.3
MAVEN_HOME: /opt/maven
  • unclick install automatically

Manage Jenkins → Manage Plugins→ Available

search maven Maven Integration & Install Maven Invoker click

Create First Maven Job

New Item → Enter an item name(Maven Project) → Edit Description

Enter an item name: my_first_maven_build

Edit Description: first maven build

Source Code Management: set up as git

Build

  • Goals and options: clean install package

Build Maven project

Resource: https://www.udemy.com/course/valaxy-devops/

ANOTE.DEV