forked from javahometech/node-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jenkinsfile-6pm-dec-2019
37 lines (36 loc) · 1.08 KB
/
jenkinsfile-6pm-dec-2019
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
pipeline {
agent any
environment{
DOCKER_TAG = getDockerTag()
}
stages{
stage('Build Docker Image'){
steps{
sh "docker build . -t kammana/nodeapp:${DOCKER_TAG} "
}
}
stage('DockerHub Push'){
steps{
withCredentials([string(credentialsId: 'docker-hub', variable: 'dockerHubPwd')]) {
sh "docker login -u kammana -p ${dockerHubPwd}"
sh "docker push kammana/nodeapp:${DOCKER_TAG}"
}
}
}
stage('Deploy to DevServer'){
steps{
sshagent (credentials: ['dev-server']) {
script{
sh returnStatus: true, script: 'ssh [email protected] docker rm -f nodeapp'
def runCmd = "docker run -d -p 8080:8080 --name=nodeapp kammana/nodeapp:${DOCKER_TAG}"
sh "ssh -o StrictHostKeyChecking=no [email protected] ${runCmd}"
}
}
}
}
}
}
def getDockerTag(){
def tag = sh script: 'git rev-parse HEAD', returnStdout: true
return tag
}