forked from javahometech/node-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
weekend-oct-jenkins-pipeline-1
29 lines (25 loc) · 1.03 KB
/
weekend-oct-jenkins-pipeline-1
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
node{
def dockerTag = getLatestCommitId()
def devIp = '172.31.6.150'
stage("SCM Checkout"){
git credentialsId: 'git-hub',
url: 'https://github.com/javahometech/node-app',
branch: 'master'
}
stage('Docker - Build & Push'){
sh script: "docker build . -t kammana/node-app:${dockerTag} "
withCredentials([string(credentialsId: 'docker-hub', variable: 'dockerHubPwd')]) {
sh script: "docker login -u kammana -p ${dockerHubPwd}"
}
sh script: "docker push kammana/node-app:${dockerTag}"
}
stage('Dev Deploy'){
sh returnStatus: true, script: "ssh ec2-user@${devIp} docker rm -f nodeapp"
sh returnStatus: true, script: 'ssh ec2-user@${devIp} docker rmi $(docker images | grep kammana/node-app | awk \'{print $3}\')'
sh "ssh ec2-user@${devIp} docker run -d -p 8080:8080 --name=nodeapp kammana/node-app:${dockerTag}"
}
}
def getLatestCommitId(){
def commitId = sh returnStdout: true, script: 'git rev-parse HEAD'
return commitId
}