-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
41 lines (39 loc) · 1.42 KB
/
Jenkinsfile
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
pipeline {
agent any
environment{
DOCKER_TAG = getDockerTag()
NEXUS_URL = "172.31.34.232:8080"
IMAGE_URL_WITH_TAG = "${NEXUS_URL}/node-app:${DOCKER_TAG}"
}
stages{
stage('Build Docker Image'){
steps{
sh "docker build . -t ${IMAGE_URL_WITH_TAG}"
}
}
stage('Nexus Push'){
steps{
withCredentials([string(credentialsId: 'nexus-pwd', variable: 'nexusPwd')]) {
sh "docker login -u admin -p ${nexusPwd} ${NEXUS_URL}"
sh "docker push ${IMAGE_URL_WITH_TAG}"
}
}
}
stage('Docker Deploy Dev'){
steps{
sshagent(['tomcat-dev']) {
withCredentials([string(credentialsId: 'nexus-pwd', variable: 'nexusPwd')]) {
sh "ssh [email protected] docker login -u admin -p ${nexusPwd} ${NEXUS_URL}"
}
// Remove existing container, if container name does not exists still proceed with the build
sh script: "ssh [email protected] docker rm -f nodeapp", returnStatus: true
sh "ssh [email protected] docker run -d -p 8080:8080 --name nodeapp ${IMAGE_URL_WITH_TAG}"
}
}
}
}
}
def getDockerTag(){
def tag = sh script: 'git rev-parse HEAD', returnStdout: true
return tag
}