forked from OpqTech/java-example
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJenkinsfile
More file actions
79 lines (70 loc) · 2.66 KB
/
Jenkinsfile
File metadata and controls
79 lines (70 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
pipeline {
agent { label 'dev' } // Specify the label of your Jenkins Slave. Modify 'dev' if you use a different label.
environment {
MAVEN_HOME = tool name: 'Maven' // Ensure 'Maven' matches the name in Jenkins tool configuration.
SONARQUBE_SERVER = 'sonar' // Define the SonarQube server ID.
SONAR_SCANNER_HOME = tool name: 'SonarScanner' // Ensure 'SonarScanner' matches the name in Jenkins tool configuration.
ARTIFACTORY_SERVER = 'Artifactory' // Define Artifactory server ID.
SONAR_TOKEN = 'squ_485c5e56e285bf09f85abbd83cb9ac6d4c73f329' // SonarQube token
}
stages {
stage('Checkout') {
steps {
// Checkout the source code from your repository
git url: 'https://github.com/shashank1553/java-example.git', branch: 'master'
}
}
stage('Build') {
steps {
// Build the Maven project
sh "${MAVEN_HOME}/bin/mvn clean install"
}
}
stage('SonarQube Analysis') {
steps {
// Run SonarQube analysis
withSonarQubeEnv(SONARQUBE_SERVER) {
sh "${MAVEN_HOME}/bin/mvn sonar:sonar -Dsonar.login=${SONAR_TOKEN}"
}
}
}
stage('Deploy to Artifactory') {
steps {
script {
// Upload artifacts to JFrog Artifactory
rtUpload (
serverId: 'Artifactory',
spec: '''{
"files": [{
"pattern": "target/works-with-heroku-1.0.war",
"target": "maven-releases/works-with-heroku/"
}]
}'''
)
}
}
}
stage('Deploy to Tomcat') {
steps {
script {
// Deploy the WAR file to Apache Tomcat server
sh """
curl -u admin:Admin12345 "http://184.73.144.199:8081/artifactory/maven-releases/works-with-heroku/works-with-heroku-1.0.war" | \
curl -u admin:123456 -X PUT "http://98.81.160.3:8080/manager/text/deploy?path=/works-with-heroku&update=true" --upload-file -
"""
}
}
}
}
post {
always {
cleanWs() // Clean the workspace after the build
}
success {
echo "Build, Analysis, and Deployment succeeded!"
}
failure {
echo "Build failed. Check the logs!"
}
}
}