Step-by-Step Guide to Deploy addressbook.war Application
Rohit Wasnik
DevOps Engineer @ANALEC | Jenkins | Kubernates | Terraform | Docker | AWS | Shell Scripting
Step 1: Set Up Version Control
Step 2: Set Up Jenkins
Step 3: Configure Jenkins Job
Example Jenkinsfile:
pipeline {
agent any
stages {
stage('Checkout') {
steps {
// Checkout the code from the repository
git 'https://github.com/Rohit2k00/addressbook.git'
}
}
stage('Build') {
steps {
// Build the .war file using Maven
sh 'mvn clean package'
}
}
stage('Test') {
steps {
// Run unit tests
sh 'mvn test'
}
}
stage('Deploy') {
steps {
// Deploy the .war file to the Tomcat server
deployToTomcat()
}
}
}
post {
success {
echo 'Deployment successful!'
}
failure {
echo 'Deployment failed!'
}
}
领英推荐
}
def deployToTomcat() {
// Define server details
def server = 'your-production-server'
def user = 'your-username'
def password = 'your-password'
def remotePath = '/path/to/tomcat/webapps'
// Transfer the .war file to the Tomcat server
sh """
sshpass -p ${password} scp target/addressbook.war ${user}@${server}:${remotePath}
"""
// Restart Tomcat to deploy the new .war file
sh """
sshpass -p ${password} ssh ${user}@${server} "sudo systemctl restart tomcat"
"""
}
Step 4: Configure Maven
Example pom.xml snippet:
<packaging>war</packaging>
<build>
<finalName>addressbook</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.3</version>
</plugin>
</plugins>
</build>
Step 5: Install and Configure Tomcat Server
Step 6: Run Jenkins Pipeline
Step 7: Monitor and Validate
Step 8: Implement Rollback Strategy
Additional Considerations
By following these steps, you can set up a robust CI/CD pipeline to deploy your addressbook.war application to a production environment efficiently and reliably.