-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
ci-cd-docker-declarative
44 lines (42 loc) · 1.31 KB
/
ci-cd-docker-declarative
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
pipeline{
agent any
tools {
maven 'maven3'
}
stages{
stage('Maven Build'){
steps{
sh "mvn clean package"
}
}
stage('Docker Build'){
steps{
sh "docker build . -t kammana/mywebapp:${dockerTag()}"
}
}
stage('DockerHub Push Image'){
steps{
withCredentials([string(credentialsId: 'docker-hub', variable: 'dockerPwd')]) {
sh "docker login -u kammana -p ${dockerPwd}"
}
sh "docker push kammana/mywebapp:${dockerTag()}"
}
}
stage('Docker Deploy Dev'){
steps{
sshagent(['docker-host-dev']) {
script{
def dkrRun = "docker run -d -p 8080:8080 --name mywebapp kammana/mywebapp:${dockerTag()}"
sh script: "ssh -o StrictHostKeyChecking=no [email protected] docker rm -f mywebapp",
returnStatus: true
sh "ssh -o StrictHostKeyChecking=no [email protected] ${dkrRun}"
}
}
}
}
}
}
def dockerTag(){
def commitId = sh returnStdout: true, script: 'git rev-parse --short HEAD'
return commitId
}