-
Notifications
You must be signed in to change notification settings - Fork 8.6k
/
2019-Aug-9:30Am-jenkinsfile
44 lines (37 loc) · 1.2 KB
/
2019-Aug-9:30Am-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
node('master'){
// Add maven to path
env.PATH = "/opt/maven3/bin/:$PATH"
stage('Git Clone/Pull'){
git branch: 'dev',
url: 'https://github.com/javahometech/my-app'
}
stage('Build Docker Image'){
sh "mvn clean package"
sh "mv target/*.war target/myweb.war"
sh "docker build -t kammana/my-app:1.0 ."
}
stage('Push Image'){
withCredentials([string(credentialsId: 'docker-hub', variable: 'dockerHubPwd')]) {
sh "docker login -u kammana -p ${dockerHubPwd}"
}
sh "docker push kammana/my-app:1.0"
}
stage('Delete Old Container'){
sshagent (credentials: ['dev-docker']) {
try{
def dockrRm = "docker rm -f my-app"
def dockrRmImage = "docker rmi kammana/my-app:1.0"
sh "ssh -o StrictHostKeyChecking=no [email protected] ${dockrRm} "
sh "ssh -o StrictHostKeyChecking=no [email protected] ${dockrRmImage} "
}catch(e){
echo "container my-app not found"
}
}
}
stage('Deploy On Dev'){
sshagent (credentials: ['dev-docker']) {
def dockerRun = "docker run -d -p 8080:8080 --name=my-app kammana/my-app:1.0"
sh "ssh -o StrictHostKeyChecking=no [email protected] ${dockerRun} "
}
}
}