forked from frontalnh/temp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
158 lines (132 loc) · 4.08 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
pipeline {
// 스테이지 별로 다른 거
agent any // 아무 slave나
triggers {
pollSCM('*/3 * * * *') //3분주기. cron 문법
}
environment {
AWS_ACCESS_KEY_ID = credentials('awsAccessKeyId') // AWS에 대한 환경 변수 등록. IAM에서 받아 오는 것.
AWS_SECRET_ACCESS_KEY = credentials('awsSecretAccessKey')
AWS_DEFAULT_REGION = 'ap-northeast-2'
HOME = '.' // Avoid npm root owned
}
stages {
// 레포지토리를 다운로드 받음
stage('Prepare') {
agent any
steps {
echo 'Clonning Repository'
git url: 'https://github.com/frog97/temp.git',
branch: 'master',
credentialsId: 'frog97'
}
post {
// If Maven was able to run the tests, even if some of the test
// failed, record the test results and archive the jar file.
success {
echo 'Successfully Cloned Repository'
}
always {
echo "i tried..."
}
cleanup {
echo "after all other post condition"
}
}
}
// aws s3 에 파일을 올림
stage('Deploy Frontend') {
steps {
echo 'Deploying Frontend'
// 프론트엔드 디렉토리의 정적파일들을 S3 에 올림, 이 전에 반드시 EC2 instance profile 을 등록해야함.
dir ('./website'){
sh '''
aws s3 sync ./ s3://testhhyoontest
'''
}
}
post {
// If Maven was able to run the tests, even if some of the test
// failed, record the test results and archive the jar file.
success {
echo 'Successfully Cloned Repository'
mail to: 'frog97@gmail.com',
subject: "Deploy Frontend Success",
body: "Successfully deployed frontend!"
}
failure {
echo 'I failed :('
mail to: 'frog97@gmail.com',
subject: "Failed Pipelinee",
body: "Something is wrong with deploy frontend"
}
}
}
stage('Lint Backend') {
// Docker plugin and Docker Pipeline 두개를 깔아야 사용가능!
agent {
docker {
image 'node:latest'
}
}
steps {
dir ('./server'){
sh '''
npm install&&
npm run lint
'''
}
}
}
stage('Test Backend') {
agent {
docker {
image 'node:latest'
}
}
steps {
echo 'Test Backend'
dir ('./server'){
sh '''
npm install
npm run test
'''
}
}
}
stage('Bulid Backend') {
agent any
steps {
echo 'Build Backend'
dir ('./server'){
sh """
docker build . -t server --build-arg env=${PROD}
"""
}
}
post {
failure {
error 'This pipeline stops here...'
}
}
}
stage('Deploy Backend') {
agent any
steps {
echo 'Build Backend'
dir ('./server'){
sh '''
docker run -p 80:80 -d server
'''
}
}
post {
success {
mail to: 'frog97@gmail.com',
subject: "Deploy Success",
body: "Successfully deployed!"
}
}
}
}
}