forked from javahometech/my-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipeline-docker-ci-cd
41 lines (37 loc) · 1.09 KB
/
pipeline-docker-ci-cd
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
node{
stage('Git Checkout'){
git url: 'https://github.com/javahometech/my-app',
branch:'master'
}
stage('MVN Package'){
def mvnHome = tool name: 'maven-3', type: 'maven'
sh "${mvnHome}/bin/mvn clean package"
}
stage('Build Docker Image'){
sh 'docker build -t kammana/my-app:0.0.1 .'
}
stage('Upload Image to DockerHub'){
withCredentials([string(credentialsId: 'docker-hub', variable: 'password')]) {
sh "docker login -u kammana -p ${password}"
}
sh 'docker push kammana/my-app:0.0.1'
}
stage('Remove Old Containers'){
sshagent(['my-app-dev']) {
try{
def sshCmd = 'ssh -o StrictHostKeyChecking=no [email protected]'
def dockerRM = 'docker rm -f my-app'
sh "${sshCmd} ${dockerRM}"
}catch(error){
}
}
}
stage('Deploy-Dev'){
sshagent(['my-app-dev']) {
input 'Deploy to Dev?'
def sshCmd = 'ssh -o StrictHostKeyChecking=no [email protected]'
def dockerRun = 'docker run -d -p 8080:8080 --name my-app kammana/my-app:0.0.1'
sh "${sshCmd} ${dockerRun}"
}
}
}