-
Notifications
You must be signed in to change notification settings - Fork 8.6k
/
docker-ci-cd
41 lines (34 loc) · 976 Bytes
/
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 'https://github.com/javahometech/my-app'
}
stage('Maven Package'){
sh 'mvn clean package'
sh 'mv target/myweb*.war target/myweb.war'
}
stage('Build Docker Imager'){
sh 'docker build -t kammana/myweb:0.0.1 .'
}
stage('Push to Docker Hub'){
withCredentials([string(credentialsId: 'github-pwd', variable: 'dockerHubPwd')]) {
sh "docker login -u kammana -p ${dockerHubPwd}"
}
sh 'docker push kammana/myweb:0.0.1'
}
stage('Remove Previous Container'){
try{
def dockerRm = 'docker rm -f myweb'
sshagent(['docker-dev']) {
sh "ssh -o StrictHostKeyChecking=no [email protected] ${dockerRm}"
}
}catch(error){
// do nothing if there is an exception
}
}
stage('Deploy to Dev Environment'){
def dockerRun = 'docker run -d -p 8080:8080 --name myweb kammana/myweb:0.0.1 '
sshagent(['docker-dev']) {
sh "ssh -o StrictHostKeyChecking=no [email protected] ${dockerRun}"
}
}
}