Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
15a612c
Update pom.xml
SaravanaNani Jun 27, 2024
dcbcd13
Update pom.xml
SaravanaNani Jul 3, 2024
c4f355c
Update pom.xml
SaravanaNani Jul 5, 2024
b9acc82
Update pom.xml
SaravanaNani Jul 5, 2024
3e65169
Update pom.xml
SaravanaNani Jul 5, 2024
d69e652
Update pom.xml
SaravanaNani Jul 5, 2024
98e60e5
Update version to 1.2.47
SaravanaNani Jul 5, 2024
6385bd0
Update pom.xml
SaravanaNani Jul 5, 2024
cac7827
Update pom.xml
SaravanaNani Jul 5, 2024
1ef92c4
Update version to 1.2.19
SaravanaNani Jul 5, 2024
a5f313a
Update pom.xml
SaravanaNani Jul 5, 2024
cf41f81
Update pom.xml
SaravanaNani Jul 5, 2024
a9fc832
Update version to 1.2.21
SaravanaNani Jul 5, 2024
465e0e0
Create Jenkinsfile
SaravanaNani Jul 5, 2024
8ee082c
Update pom.xml
SaravanaNani Jul 5, 2024
96f7951
Update version to 1.2.25
SaravanaNani Jul 5, 2024
fd82554
Update version to 1.2.26
SaravanaNani Jul 5, 2024
eded4e1
Update Jenkinsfile
SaravanaNani Jul 5, 2024
896c529
Update version to 1.2.28
SaravanaNani Jul 5, 2024
7750524
Update Jenkinsfile
SaravanaNani Jul 8, 2024
58ab720
Update Jenkinsfile
SaravanaNani Jul 8, 2024
7e51299
Update Jenkinsfile
SaravanaNani Jul 8, 2024
2a99474
Update version to 1.2.32
SaravanaNani Jul 8, 2024
4040b89
Update version to 1.2.34
SaravanaNani Jul 8, 2024
25a4ed0
Update version to 1.2.36
SaravanaNani Jul 8, 2024
5af3ad2
Update Jenkinsfile
SaravanaNani Jul 8, 2024
c45006e
Update Jenkinsfile
SaravanaNani Jul 9, 2024
bde0b9c
Update version to 1.2.42
SaravanaNani Jul 9, 2024
ef77bb9
Update Jenkinsfile
SaravanaNani Jul 9, 2024
0fc72ed
Update version to 1.2.43
SaravanaNani Jul 9, 2024
d225561
Update pom.xml
SaravanaNani Jul 10, 2024
ced67b4
Update pom.xml
SaravanaNani Jul 11, 2024
a6e93ae
Update pom.xml
SaravanaNani Jul 11, 2024
4b6c5ce
Update version to 1.2.104
SaravanaNani Jul 11, 2024
e2a20c3
Update Jenkinsfile
SaravanaNani Jul 11, 2024
65cda94
Update version to 1.2.106
SaravanaNani Jul 11, 2024
e8e518b
Update version to 1.2.32
SaravanaNani Jul 13, 2024
4fb6073
Update version to 1.2.33
SaravanaNani Jul 13, 2024
edec520
Update version to 1.2.37
SaravanaNani Jul 13, 2024
bcdc3b5
Update version to 1.2.38
SaravanaNani Jul 13, 2024
c5d2377
Update version to 1.2.49
SaravanaNani Jul 13, 2024
05098fd
Update version to 1.2.51
SaravanaNani Jul 13, 2024
9f5c45d
Update version to 1.2.53
SaravanaNani Jul 13, 2024
55e02e9
Create Jenkinsfile-1
SaravanaNani Jul 13, 2024
a0c17ca
Update version to 1.2.109
SaravanaNani Jul 13, 2024
38813cd
Update Jenkinsfile-1
SaravanaNani Jul 13, 2024
49ac5cf
Update Jenkinsfile
SaravanaNani Jul 13, 2024
9196c2c
Delete Jenkinsfile-1
SaravanaNani Jul 13, 2024
4088f5c
Update pom.xml
SaravanaNani Jul 15, 2024
1142b1d
Update Jenkinsfile
SaravanaNani Jul 15, 2024
682881e
Update version to 1.2.113
SaravanaNani Jul 15, 2024
925d480
Update version to 1.2.2
SaravanaNani Jul 25, 2024
8f74271
Update Jenkinsfile
SaravanaNani Aug 8, 2024
bbc9dd9
Update Jenkinsfile
SaravanaNani Aug 8, 2024
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
174 changes: 174 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
pipeline {
agent {
label 'docker'
}
tools {
maven 'maven'
}
environment {
WORKSPACE_DIR = '/var/lib/jenkins/workspace/adq-java-app'
PROJECT_ID = 'gcp-adq-pocproject-dev'
ZONE = 'us-central1-c'
INSTANCE_NAME = 'get-ubuntudesktop'
TARGET_HOST_PATH = '/opt/tomcat/apache-tomcat-10.1.28'
SONARQUBE_PROJECT_KEY = 'adq-java-app'
SONARQUBE_HOST_URL = 'http://34.69.178.242:9000'
NEXUS_URL = '34.69.178.242:8081'
NEXUS_REPOSITORY = 'adq-java-app'
NEXUS_GROUP_ID = 'in.ADQ-JAVA-APP'
NEXUS_ARTIFACT_ID = 'JAVA_APP'
NEXUS_VERSION = 'nexus3'
NEXUS_PROTOCOL = 'http'
SSH_KEY_PATH = '/var/lib/jenkins/.ssh/id_rsa'
ADMIN_EMAIL = 'getadqdevops@gmail.com'
}
stages {
stage('Checkout') {
steps {
script {
def gitInfo = checkout([$class: 'GitSCM',
branches: [[name: "*/${BRANCH_NAME}"]],
userRemoteConfigs: [[url: 'https://github.com/SaravanaNani/jenkins-java-project.git']]
])
def branchName = gitInfo.GIT_BRANCH.tokenize('/')[1]
echo "Branch name: ${branchName}"
}
}
}
stage('SonarQube Analysis') {
steps {
withCredentials([string(credentialsId: 'sonar_token', variable: 'SONAR_TOKEN')]) {
sh '''
mvn clean verify sonar:sonar \
-Dsonar.projectKey=${SONARQUBE_PROJECT_KEY} \
-Dsonar.host.url=${SONARQUBE_HOST_URL} \
-Dsonar.login=${SONAR_TOKEN}
'''
}
}
}

stage('Package') {
steps {
sh '''
mvn compile
mvn test
mvn package
'''
}
}
stage('Upload Artifact to Nexus') {
steps {
script {
sh '''
cd ${WORKSPACE_DIR}/target/
mv JAVA_APP-1.2.*.war JAVA_APP-1.2.${BUILD_NUMBER}
'''
nexusArtifactUploader artifacts: [[artifactId: "${NEXUS_ARTIFACT_ID}", classifier: '', file: "${WORKSPACE_DIR}/target/JAVA_APP-1.2.${BUILD_NUMBER}", type: 'war']], credentialsId: 'nexus_id', groupId: "${NEXUS_GROUP_ID}", nexusUrl: "${NEXUS_URL}", nexusVersion: "${NEXUS_VERSION}", protocol: "${NEXUS_PROTOCOL}", repository: "${NEXUS_REPOSITORY}", version: "1.2.${BUILD_NUMBER}"
}
}
}
stage('Check Infrastructure and Request Approval') {
steps {
script {
def instanceStatus = sh(script: "gcloud compute instances describe ${INSTANCE_NAME} --project=${PROJECT_ID} --zone=${ZONE} --format='get(status)'", returnStdout: true).trim()
if (instanceStatus != 'RUNNING') {
error "VM instance is not running. Deployment stopped."
}
env.PRIVATE_IP = sh(script: '''
gcloud compute instances list --filter="labels.adq_ubuntudesktop=app" --format="value(networkInterfaces[0].networkIP)" --limit=1
''', returnStdout: true).trim()
echo "Private IP: ${env.PRIVATE_IP}"

emailext (
subject: "Approval Needed: Proceed with Deployment",
body: """
<p>The infrastructure is ready for deployment.</p>
<p>Instance Status: ${instanceStatus}</p>
<p>Private IP: ${env.PRIVATE_IP}</p>
<p>Please approve the execution of the deployment stage.</p>
<p>Click <a href="${env.BUILD_URL}input/">here</a> to provide approval.</p>
""",
mimeType: 'text/html',
to: "${env.ADMIN_EMAIL}"
)
echo 'Approval email sent. Awaiting manual approval...'

def userInput = input(
id: 'userInput', message: 'Approval needed to proceed with the deployment.', parameters: [
[$class: 'BooleanParameterDefinition', defaultValue: true, description: 'Approve to proceed?', name: 'Proceed']
]
)

if (!userInput) {
echo 'Aborted by user.'
currentBuild.result = 'ABORTED'
emailext (
subject: "Approval Denied: Deployment",
body: "The stage to deploy has been denied and will not be executed.",
mimeType: 'text/html',
to: "${env.ADMIN_EMAIL}"
)
error('User aborted the stage.')
}
}
}
}
stage('Deployment') {
steps {
script {
withCredentials([usernamePassword(credentialsId: 'nexus_id', usernameVariable: 'NEXUS_USER', passwordVariable: 'NEXUS_PASSWORD')]) {
sh '''
# Clear the target directory
ls -al ${WORKSPACE_DIR}/target/
rm -r ${WORKSPACE_DIR}/target/*
ls -al ${WORKSPACE_DIR}/target/

# Download the artifact from Nexus
wget --user=${NEXUS_USER} --password=${NEXUS_PASSWORD} -O ${WORKSPACE_DIR}/target/JAVA_APP-1.2.${BUILD_NUMBER}.war ${NEXUS_PROTOCOL}://${NEXUS_URL}/repository/${NEXUS_REPOSITORY}/in/ADQ-JAVA-APP/JAVA_APP/1.2.${BUILD_NUMBER}/JAVA_APP-1.2.${BUILD_NUMBER}.war

# List the target directory to confirm the file is downloaded
ls -al ${WORKSPACE_DIR}/target/

# Deployment steps
ssh -o StrictHostKeyChecking=no -i ${SSH_KEY_PATH} root@${PRIVATE_IP} "${TARGET_HOST_PATH}/bin/shutdown.sh"
ssh -o StrictHostKeyChecking=no -i ${SSH_KEY_PATH} root@${PRIVATE_IP} "find ${TARGET_HOST_PATH}/webapps/ -type d -name 'JAVA_APP-1.2.*' -exec rm -rf {} +"
ssh -o StrictHostKeyChecking=no -i ${SSH_KEY_PATH} root@${PRIVATE_IP} "find ${TARGET_HOST_PATH}/webapps/ -type f -name 'JAVA_APP-1.2*.war' -exec rm -f {} +"
scp -o StrictHostKeyChecking=no -i ${SSH_KEY_PATH} ${WORKSPACE_DIR}/target/JAVA_APP-1.2.${BUILD_NUMBER}.war root@${PRIVATE_IP}:${TARGET_HOST_PATH}/webapps/
ssh -o StrictHostKeyChecking=no -i ${SSH_KEY_PATH} root@${PRIVATE_IP} "${TARGET_HOST_PATH}/bin/startup.sh"
'''
}
}
}
}

stage('Update pom.xml Version') {
steps {
script {
sh 'git clone https://github.com/SaravanaNani/jenkins-java-project.git'
sh '''
cd jenkins-java-project
git fetch --all
git checkout ${BRANCH_NAME}
echo "Before modification:"
sed -n '7p' pom.xml
perl -i -pe 'if ($. == 7) { s|<version>.*?</version>|<version>1.2.'${BUILD_NUMBER}'</version>| }' pom.xml
echo "After modification:"
sed -n '7p' pom.xml
git config user.name "SaravanaNani"
git config user.email "saravana08052002@gmail.com"
git add pom.xml
git commit -m "Update version to 1.2.${BUILD_NUMBER}"
'''
withCredentials([string(credentialsId: 'github-pat', variable: 'GITHUB_PAT')]) {
sh '''
cd jenkins-java-project
git remote set-url origin https://$GITHUB_PAT@github.com/SaravanaNani/jenkins-java-project.git
git push origin ${BRANCH_NAME}
'''
}
}
}
}
}
}
112 changes: 64 additions & 48 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,51 +1,67 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>in.RAHAM</groupId>
<artifactId>NETFLIX</artifactId>
<packaging>war</packaging>
<version>1.2.2</version>
<name>Java Home myweb</name>
<url>http://maven.apache.org</url>

<properties>
<docker.image.prefix>kammana</docker.image.prefix>
</properties>
<dependencies>
<dependency>
<groupId>com.oracle.bedrock</groupId>
<artifactId>bedrock-runtime-maven</artifactId>
<version>5.1.2</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>in.ADQ-JAVA-APP</groupId>
<artifactId>JAVA_APP</artifactId>
<packaging>war</packaging>
<version>1.2.2</version>
<name>Java Home myweb</name>
<url>http://maven.apache.org</url>

<properties>
<docker.image.prefix>kammana</docker.image.prefix>
</properties>
<dependencies>
<dependency>
<groupId>com.oracle.bedrock</groupId>
<artifactId>bedrock-runtime-maven</artifactId>
<version>5.1.2</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<distributionManagement>
<snapshotRepository>
<id>nexusRepo</id>
<url>http://13.233.230.166:8081/repository/maven-snapshots/</url>
</snapshotRepository>

<repository>
<id>nexusRepo</id>
<url>http://13.233.230.166:8081/repository/maven-releases/</url>
</repository>
</distributionManagement>

<pluginRepositories>
<pluginRepository>
<id>maven1</id>
<name>Maven.org</name>
<url>http://repo1.maven.org/maven2</url>
</pluginRepository>
</pluginRepositories>

</dependencies>

<distributionManagement>
<snapshotRepository>
<id>nexusRepo</id>
<url>http://13.233.230.166:8081/repository/maven-snapshots/</url>
</snapshotRepository>

<repository>
<id>nexusRepo</id>
<url>http://13.233.230.166:8081/repository/maven-releases/</url>
</repository>
</distributionManagement>

<pluginRepositories>
<pluginRepository>
<id>maven1</id>
<name>Maven.org</name>
<url>http://repo1.maven.org/maven2</url>
</pluginRepository>
</pluginRepositories>


<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.2</version>
</plugin>
</plugins>
</build>
</project>