This respository is basically for all the DevOps technologies
- Open the inbound port 8080 as Jenkins listens on 8080 port.
- Check if java installed "java -version", if not then install using "yum install java-1.8*" command.
Get the java location using "$(dirname
$(dirname $ (readlink -f $(which javac))))" command. Add JAVA_HOME and java path to .bash_profile. JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-1.el7_9.x86_64 PATH=$PATH:$HOME/bin:$JAVA_HOME Run "echo $JAVA_HOME" to verify the java path. - To download and install jenkins for CentOS follow the commands on https://pkg.jenkins.io/redhat-stable/
- Update the hostname as Jenkins(If not jenkins) by running command "hostname jenkins" then exit and relogin.
- Start and enable jenkins service. systemctl status jenkins systemctl start jenkins systemctl enable jenkins
- Run below command to get the initialAdminPassword. "cat /var/lib/jenkins/secrets/initialAdminPassword"
- Open :8080 in the browser. Copy the password from step 5 and paste in browser window to login to jenkins. Select Customize jenkins (Install suggested plugins OR Select Plugins to Install). We can skip this and start using jenkins directly.
Go to Admin > Configure > Password
Jenkins > Manage Jenkins > Global Tool Configuration > JDK > Add JDK (Name:JAVA_HOME, JAVA_HOME=Java location from step 2) > Apply > Save
Jenkins > New Item > My_First_Jenkins_Job > Build (Add build step as Execute Shell as we are using Linux) > Enter echo "Hello Jenkins" > Apply > Save
Jenkins > Build Now
yum install -y git
Jenkins > Manage Jenkins > Manage Plugins > Available (search for github) > Select Github and Click on "Install without restart"
Jenkins > Manage Jenkins > Global Tool Configuration > Git > Add JDK (Name:git, Path to Git executable=/usr/bin/git) > Apply > Save
mkdir -p /opt/maven
wget https://dlcdn.apache.org/maven/maven-3/3.8.4/binaries/apache-maven-3.8.4-bin.tar.gz
tar -xzf apache-maven-3.8.4-bin.tar.gz -C /opt/maven
cd /opt/maven
mv /opt/maven/apache-maven-3.8.4/* /opt/maven
vi ~/.bash_profile
M2_HOME=/opt/maven
M2=/opt/maven/bin
PATH=$PATH:$HOME/bin:$JAVA_HOME:$M2_HOME:$M2
echo $M2
echo $M2_HOME
mvn --version
Jenkins > Manage Jenkins > Manage Plugins > Available (search for maven) > Select Maven Integration, Maven Invoker > Click on "Install without restart"
Jenkins > Manage Jenkins > Global Tool Configuration > Maven > Add Maven (Name:M2_HOME, MAVEN_HOME=/opt/maven) > Apply > Save
Now if we will create a new job in Jenkins, it will show Maven Project as well to choose. We have build environment for CI/CD pipeline.
Using Ansible, we can scrpts in Playbook which will fetch the artifacts and will generate a docker file, push it to docker hub and using that image, it will create a docker container in kubernetes.
Create Maven Project using git url https://github.com/jhawithu/hello-world.git
============================================================================================================================
yum install -y java-1.8*
Get the java location using "$(dirname $(dirname $(readlink -f $(which javac))))" command.
Add JAVA_HOME and java path to .bash_profile.
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-1.el7_9.x86_64
PATH=$PATH:$HOME/bin:$JAVA_HOME
Run "echo $JAVA_HOME" to verify the java path.
hostname tomcat
mkdir -p /opt/tomcat
wget https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.56/bin/apache-tomcat-9.0.56.tar.gz
tar -xzf apache-tomcat-9.0.56.tar.gz
mv apache-tomcat-9.0.56 /opt/tomcat/
cd /opt/tomcat/bin
./startup.sh
Verify the Tomcat installation and startup by opening :8080 in the browser. Click on manager App, it will show the permission denied because usually tomcat server should be accessed from the same machine but we are accessing it from different machine. So we need to update context.xml file on command line. We can find the context.xml files. Comment the Value Class name entries by adding in the end of the line in /opt/tomcat/webapps/manager & host-manager/META-INF/conext.xml files.
Now access the Web URL again and click on Manager App. It will ask for login username and password. As we do not have those details, we need to modify some details in /opt/tomcat/conf/tomcat-users.xml file.Then we can use tomcat/tomcat details to login to Manager App.
Login to Jenkins and install "Deploy to Container" plugin. Create a new job. Source Code Management: Git => Provide git URL https://github.com/jhawithu/hello-world.git Branches to build: */main Root POM: pom.xml Goals and options: clean install package Post Steps: Deploy war/ear to a container
Once the job will be build it will create webapp and webapp.war files under /opt/tomcat/webapps directory. Now we can check the output at <tomcat-url>:8080/webapp in the browser.