-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
54 lines (52 loc) · 1.4 KB
/
Jenkinsfile
File metadata and controls
54 lines (52 loc) · 1.4 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
pipeline {
agent any
// tools {
// maven 'Maven 3'
// }
environment {
SONAR_URL = 'http://34.87.243.235:9000'
SONAR_TOKEN = credentials('sonar-token') // Add this in Jenkins credentials
IMAGE_NAME = "myapp"
IMAGE_TAG = "latest"
}
stages {
stage('Clone Repository') {
steps {
git branch: 'main', url: 'https://github.com/ameda71/anonymoussaiteja.git'
}
}
stage('Build with Maven') {
steps {
sh 'mvn clean package'
}
}
stage('SonarQube Analysis') {
steps {
sh '''
mvn sonar:sonar \
-Dsonar.projectKey=my-project \
-Dsonar.host.url=${SONAR_URL} \
-Dsonar.token=${SONAR_TOKEN}
'''
}
}
stage('Build Docker Image') {
steps {
sh 'docker build -t ${IMAGE_NAME}:${IMAGE_TAG} .'
}
}
stage('Run Docker Container') {
steps {
sh 'docker run -d -p 8089:8089 --name myapp_container ${IMAGE_NAME}:${IMAGE_TAG}'
}
}
}
post {
success {
echo "Application successfully deployed in a Docker container!"
}
failure {
echo "Build failed!"
}
}
}