-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Expand file tree
/
Copy pathJenkinsFileDocker
More file actions
73 lines (65 loc) · 1.91 KB
/
JenkinsFileDocker
File metadata and controls
73 lines (65 loc) · 1.91 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
pipeline
{
agent any
tools
{
maven 'Maven_3.9.7'
}
environment
{
buildNumber = "${BUILD_NUMBER}"
}
stages
{
stage('Checkout Code to Jenkins from GitHub')
{
steps()
{
git branch: 'master', url: 'https://github.com/MithunTechnologiesDevOps/maven-web-application.git'
}
}
stage('Build Artifact using Maven')
{
steps()
{
sh 'mvn clean package'
}
}
stage("Build Docker Image")
{
steps()
{
sh 'docker build -t mithuntechnologies/maven-web-application:${buildNumber} .'
}
}
stage("Authenticate and Push Docker Image to Docker Hub")
{
steps()
{
withCredentials([string(credentialsId: 'Docker_Hub_Password', variable: 'Docker_Hub_Password')])
{
sh 'docker login -u mithuntechnologies -p ${Docker_Hub_Password}'
}
sh 'docker push mithuntechnologies/maven-web-application:${buildNumber}'
}
}
stage('Remove Docker Image from Jenkins Locally')
{
steps()
{
sh 'docker rmi -f mithuntechnologies/maven-web-application:${buildNumber}'
}
}
stage('Deploy Application to Deployment Server')
{
steps()
{
sshagent(['DeploymentServer_SSH'])
{
sh "ssh -o StrictHostKeyChecking=no ubuntu@3.108.196.56 docker rm -f mavenwebapplication || true"
sh "ssh -o StrictHostKeyChecking=no ubuntu@3.108.196.56 docker run -d --name mavenwebapplication -p 8080:8080 mithuntechnologies/maven-web-application:$Build_Number"
}
}
}
}
}