forked from devops2341/source-maven-java-spring-hello-webapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile-docker
59 lines (57 loc) · 1.36 KB
/
Jenkinsfile-docker
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
pipeline {
agent none
stages {
stage('Checkout') {
agent any
steps {
git branch: 'main', url: 'https://github.com/ax0413/test-app'
}
}
stage('Build') {
agent {
docker { image 'maven:3-openjdk-17' }
}
steps {
sh 'mvn clean package -DskipTests=true'
}
}
stage('Test') {
agent {
docker { image 'maven:3-openjdk-17' }
}
steps {
sh 'mvn test'
}
}
stage('Build Docker Image') {
agent any
steps {
sh 'docker image build -t webapp:hello-world .'
}
}
stage('Tag Docker Image') {
agent any
steps {
sh 'docker image tag webapp:hello-world nsyoun/webapp:$BUILD_NUMBER'
sh 'docker image tag webapp:hello-world nsyoun/webapp:latest'
}
}
stage('Publish Docker Image') {
agent any
steps {
withDockerRegistry(credentialsId: 'docker-hub-token', url: 'https://index.docker.io/v1/') {
sh 'docker image push nsyoun/webapp:$BUILD_NUMBER'
sh 'docker image push nsyoun/webapp:latest'
}
}
}
stage('Run Docker Container') {
agent {
docker { image 'docker:dind' }
}
steps {
sh 'docker -H tcp://192.168.56.103:2375 container run --detach --name webapp -p 80:8080 nsyoun/webapp:$BUILD_NUMBER'
}
}
}
}