Learn to Establish a Target Environment Using Jenkins
Tomcat Web Application Server
Jenkins_Master Node(VM)
Install jdk,jenkins,git.
Used to Create the CI/CD Pipeline Projects and schedule to run in slave nodes.
Jenkins_Slave Node(VM)
To Execute the Application Build.
Perform Application Build - Compile, Unit Test, Create Artifacts
Tomcat_Server (VM)
To Execute and Test the Application Artifacts (*.war)
Install jdk, Tomcat.
Tomcat runs in port 8080
Install Tomcat server on ubuntu and configure
Launch New Node - Ubuntu - 22.04 ami
- Enable port 8080
Install Tomcat :: https://tomcat.apache.org/download-80.cgi
sudo -i
apt update -y
apt-get install default-jdk -y
java --version
cd /opt/
wget https://archive.apache.org/dist/tomcat/tomcat-8/v8.5.99/bin/apache-tomcat-8.5.99.tar.gz
tar -xvzf /opt/apache-tomcat-8.5.99.tar.gz
mv apache-tomcat-8.5.99 tomcat
cd tomcat/bin/
./startup.sh # Used to Start the Tomcat Server
Open web browser :
http://<Public_IP_Address>:8080/
Add User
useradd <username> -s /bin/bash -m -d /home/<username>
su - <username>
ssh-keygen
make created user as a owner to tomcat dir
- chown -R <username> /opt/tomcat - run as a root user
Publish Over SSH Plugin is used to copy the artifacts from Jenkins Slave Node to Tomcat Server
- Install Publish Over SSH Plugin in Jenkins Master.
Deployment
Creation of target server
Click on manage Jenkins
Click on system
Scroll to the bottom and find the Publish over SSH section, then click on "Add" to add an SSH server.
Enter the name, hostname, username, and remote directory. Then click on Advanced
Check the "Use password authentication, or use a different key" option and add private keys in the keys field.
Click on "Test Configuration," and a success status should be displayed.
Update the Pipeline with the deployment parameter using pipeline snippet generator
Select
sshPublisher
from the snippet generator dropdown.Add the source file, remove the prefix, and specify the remote directory, then click on generate pipeline script.
Once pipeline script is ready, add script to the pipeline
pipeline { agent { label 'slave' } stages { stage('SCM_Checkout') { steps { echo "Perform SCM Checkout" git 'https://github.com/SA-Team-DevOps-03-Dec-24/java-mvn-springbootapp.git' } } stage('Application Build') { steps { echo "Perform Application Build" sh 'mvn clean package' } } stage('Deploy to the test server') { steps { script{ sshPublisher(publishers: [sshPublisherDesc(configName: 'tomcat_server', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: '', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '.', remoteDirectorySDF: false, removePrefix: 'target/', sourceFiles: '/target/*.war')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)]) } } } } }
Save and run build
Deployment is done
war file is copied to tomcat_server
Now copy the public IP of the Tomcat server, access it using port 8080, and add the artifact name.