forked from bhagyashreep032/docker-sample-java-webapp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
41 lines (36 loc) · 1.18 KB
/
Jenkinsfile
File metadata and controls
41 lines (36 loc) · 1.18 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
pipeline {
agent any
environment {
IMAGE_NAME = 'java-webapp'
DOCKER_HUB_USER = credentials('dockerhub-cred')
}
stages {
stage('Check Docker Access') {
steps {
sh 'docker version'
}
}
stage('Build Docker Image') {
steps {
sh 'docker build -t java-webapp:latest .'
}
}
stage('Push Docker Image') {
steps {
withCredentials([usernamePassword(credentialsId: 'dockerhub-cred', usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) {
sh '''
echo "$DOCKER_PASS" | docker login -u "$DOCKER_USER" --password-stdin
docker tag java-webapp:latest $DOCKER_USER/java-webapp:latest
docker push $DOCKER_USER/java-webapp:latest
'''
}
}
}
stage('Deploy') {
steps {
//sh 'docker run -d --name java-webapp-container java-webapp:latest'
sh 'docker run -d --name java-webapp-container2 -p 8080:8080 java-webapp:latest'
}
}
}
}