forked from Youssef-Choura/BookApp
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathJenkinsfile_Docker_2025
More file actions
56 lines (51 loc) · 1.61 KB
/
Jenkinsfile_Docker_2025
File metadata and controls
56 lines (51 loc) · 1.61 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
pipeline {
agent { node { label 'AWSNode' } }
tools {
// Install the Maven version configured as "M3" and add it to the path.
maven "M3"
jdk 'JDK17'
maven 'Maven_3911'
}
environment {
DOCKERREPO_NAME = "bookapplication"
myDockerhub = "mohanraj123"
}
stages {
stage('CleanWS') {
steps {
cleanWs()
}
}
stage('Clone the repo') {
steps {
git 'https://github.com/mohansgithub/BookApp.git'
}
}
stage('maven build'){
steps {
sh 'mvn clean package'
}
}
stage('docker deployment'){
steps {
withCredentials([usernamePassword(credentialsId: 'a5f262f6-c681-4959-b5e7-035182ddd855', passwordVariable: 'DOCKERHUB_PASS', usernameVariable: 'DOCKERHUB_NAME')]) {
sh '''
docker login -u ${DOCKERHUB_NAME} -p ${DOCKERHUB_PASS}
sudo docker build -t ${DOCKERHUB_NAME}/${DOCKERREPO_NAME}:${BUILD_NUMBER} .
sudo docker push ${DOCKERHUB_NAME}/${DOCKERREPO_NAME}:${BUILD_NUMBER}
sudo docker images
sudo docker ps -f name=${myDockerRepoName} -q | xargs --no-run-if-empty sudo docker container stop
sudo docker container ls -a -fname=${myDockerRepoName} -q | xargs -r sudo docker container rm
sudo docker system prune -f
sudo docker run -d -p 8080:8080 ${DOCKERHUB_NAME}/${DOCKERREPO_NAME}:${BUILD_NUMBER}
'''
}
}
}
stage('mvn test') {
steps {
echo "my step";
}
}
}
}