-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsFile
More file actions
62 lines (52 loc) · 1.66 KB
/
JenkinsFile
File metadata and controls
62 lines (52 loc) · 1.66 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
pipeline {
agent any
environment {
SSH_HOST = 'ubuntu@192.168.5.61'
SSH_CRED_ID = '2-ssh-key'
IMAGE_NAME = "hamgeonwook/stockport_front:${env.BUILD_NUMBER}"
}
tools {
nodejs "nodeJs"
}
stages {
stage('git clone') {
steps {
git branch: 'develop', credentialsId: 'github-signin', url: 'https://github.com/shinhan-intern-project/frontend.git'
}
}
stage('Build Nginx') {
steps {
script {
def nginxImage = docker.build('hamgeonwook/stockport_front', '--file Dockerfile .')
docker.withRegistry('https://registry.hub.docker.com/repository/docker/hamgeonwook/stockport_front/', 'dockerHubPwd') {
nginxImage.push("${env.BUILD_NUMBER}")
}
}
}
}
stage('Deploy to web Server') {
steps {
sshagent (credentials: [SSH_CRED_ID]) {
sh """
ssh -o StrictHostKeyChecking=no $SSH_HOST '
set -e
docker pull $IMAGE_NAME || exit 1
docker stop frontend || true
docker rm frontend || true
docker image prune -f
docker run -d --name frontend -p 80:80 $IMAGE_NAME
'
"""
}
}
}
}
post {
success {
echo "SUCCESS: Job ${env.JOB_NAME}"
}
failure {
echo "FAIL: Job ${env.JOB_NAME}"
}
}
}