forked from stoenpav-flutterint/spring-with-maven
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
74 lines (61 loc) · 1.59 KB
/
Jenkinsfile
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
pipeline {
agent {
label 'mygroupagent'
}
tools{
maven 'maven'
dockerTool 'docker'
}
triggers{
githubPush()
}
environment {
DOCKERHUB_CREDENTIALS = credentials('docker_id')
IMAGE_NAME = 'stkraych/spring-with-maven'
}
stages {
stage('Clone Repo') {
steps {
git branch: 'main', url: 'https://github.com/stkraych/spring-with-maven.git'
}
}
stage('Build') {
steps {
sh 'mvn clean install'
}
}
stage('Test') {
steps {
sh 'mvn test'
}
}
stage('Docker login'){
steps {
sh 'docker login -u $DOCKERHUB_CREDENTIALS_USR -p $DOCKERHUB_CREDENTIALS_PSW'
}
}
stage('Docker build and tag'){
steps {
sh 'docker build -t ${IMAGE_NAME} -f Dockerfile .'
sh 'docker tag ${IMAGE_NAME} ${IMAGE_NAME}:${BUILD_NUMBER}'
}
}
stage('Docker Push'){
steps {
sh 'docker push ${IMAGE_NAME}:${BUILD_NUMBER}'
}
}
stage('Docker Deploy'){
steps{
sh 'docker run -d -p 4000:8080 ${IMAGE_NAME}:${BUILD_NUMBER}'
// sh 'docker container rm -f spring-with-maven || true'
// sh 'docker container run -d -p 4000:3000 --name spring-with-maven stkraych/spring-with-maven'
}
}
stage('Clean') {
steps {
cleanWs()
}
}
}
}