Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions Jenkins-Declarative-PL
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
pipeline {
agent any

environment {
DEPLOY_SERVER = '34.232.91.67'
DEPLOY_USER = 'ec2-user'
DEPLOY_DIR = '/opt/tomcat/webapps/'
}

tools {
maven 'maven3.9.9'
}

stages {

stage('Checkout') {
steps {
git branch: 'Devlop', credentialsId: '84b9e77b-9119-44b3-8f82-9239c7f2fc0f', url: 'https://github.com/usharaniwin/maven-web-app-project.git'
}
}

stage('Build') {
steps {
sh 'mvn clean package'
}
}

// Optional SonarQube Stage (commented out)
/*
stage('Sonar') {
steps {
sh 'mvn clean sonar:sonar'
}
}
*/

stage('Nexus') {
steps {
sh 'mvn clean deploy'
}
}

stage('SSH_Deploy') {
steps {
sshagent(['ssh-cred']) {
sh '''
ssh -o StrictHostKeyChecking=no ${DEPLOY_USER}@${DEPLOY_SERVER} "sudo chmod -R 777 ${DEPLOY_DIR}"
scp -o StrictHostKeyChecking=no target/maven-web-application.war ${DEPLOY_USER}@${DEPLOY_SERVER}:/tmp/
ssh -o StrictHostKeyChecking=no ${DEPLOY_USER}@${DEPLOY_SERVER} "sudo mv /tmp/maven-web-application.war ${DEPLOY_DIR}"
'''
}
}
}
}
}
30 changes: 30 additions & 0 deletions Jenkins-scripted-PL
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
node {
def mavenHome = tool name: "maven3.9.9", type: 'maven'

stage('Checkout') {
git branch: 'Devlop', credentialsId: '84b9e77b-9119-44b3-8f82-9239c7f2fc0f',
url: 'https://github.com/usharaniwin/maven-web-app-project.git'
}
stage('Compile') {
sh "${mavenHome}/bin/mvn clean compile"
}
stage('Build') {
sh "${mavenHome}/bin/mvn clean package"
}
stage('Sonar Report') {
sh "${mavenHome}/bin/mvn sonar:sonar"
}
stage('Deploy to Nexus') {
//curl -u admin:password123 http://3.92.105.74:8081/repository/abc-snapshot/
sh "${mavenHome}/bin/mvn clean deploy"
}
stage('Deploy to Tomacat')
{
sh """
curl -u svs:svs123 \
--upload-file /var/lib/jenkins/workspace/Jenkins-PL/target/maven-web-application.war \
"http://34.232.91.67:8080/manager/text/deploy?path=/maven-web-application&update=true"
"""
}

}
55 changes: 55 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
pipeline {
agent any

environment {
DEPLOY_SERVER = '34.232.91.67'
DEPLOY_USER = 'ec2-user'
DEPLOY_DIR = '/opt/tomcat/webapps/'
}

tools {
maven 'maven3.9.9'
}

stages {

stage('Checkout') {
steps {
git branch: 'Devlop', credentialsId: '84b9e77b-9119-44b3-8f82-9239c7f2fc0f', url: 'https://github.com/usharaniwin/maven-web-app-project.git'
}
}

stage('Build') {
steps {
sh 'mvn clean package'
}
}

// Optional SonarQube Stage (commented out)
/*
stage('Sonar') {
steps {
sh 'mvn clean sonar:sonar'
}
}
*/

stage('Nexus') {
steps {
sh 'mvn clean deploy'
}
}

stage('SSH_Deploy') {
steps {
sshagent(['ssh-cred']) {
sh '''
ssh -o StrictHostKeyChecking=no ${DEPLOY_USER}@${DEPLOY_SERVER} "sudo chmod -R 777 ${DEPLOY_DIR}"
scp -o StrictHostKeyChecking=no target/maven-web-application.war ${DEPLOY_USER}@${DEPLOY_SERVER}:/tmp/
ssh -o StrictHostKeyChecking=no ${DEPLOY_USER}@${DEPLOY_SERVER} "sudo mv /tmp/maven-web-application.war ${DEPLOY_DIR}"
'''
}
}
}
}
}
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
<spring.version>5.3.34</spring.version>
<junit.version>4.11</junit.version>
<log4j.version>1.2.17</log4j.version>
<sonar.host.url>http://54.221.74.74:9000/</sonar.host.url>
<sonar.host.url>http://54.234.215.68:9000/</sonar.host.url>
<sonar.login>admin</sonar.login>
<sonar.password>passw0rd</sonar.password>
<sonar.password>Sonar@123</sonar.password>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

Expand Down Expand Up @@ -98,13 +98,13 @@
<repository>
<id>nexus</id>
<name>KK FUNDA Releases Nexus Repository</name>
<url>http://172.31.40.189:8081/repository/flipkart-release/</url>
<url>http://3.92.105.74:8081/repository/abc-release/</url>
</repository>

<snapshotRepository>
<id>nexus</id>
<name>KK FUNDA Snapshot Nexus Repository </name>
<url>http://172.31.40.189:8081/repository/flipkart-snapshot/</url>
<url>http://3.92.105.74:8081/repository/abc-snapshot/</url>
</snapshotRepository>

</distributionManagement>
Expand Down