-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
149 lines (138 loc) · 5.3 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
pipeline {
agent any
tools {nodejs "nodejs"}
environment {
NODE_ENV = 'development'
PORT = 3100
HOST = "${env.GITHUB_ENV.HOST}"
MONGODB_URL = "${env.GITHUB_ENV.MONGODB_URL}"
JWT_SECRET = "${env.GITHUB_ENV.JWT_SECRET}"
JWT_ACCESS_EXPIRATION_MINUTES = 30
JWT_REFRESH_EXPIRATION_DAYS = 30
JWT_RESET_PASSWORD_EXPIRATION_MINUTES = 10
JWT_VERIFY_EMAIL_EXPIRATION_MINUTES = 10
SMTP_HOST = "${env.GITHUB_ENV.SMTP_HOST}"
SMTP_PORT = 587
SMTP_USERNAME = "${env.GITHUB_ENV.SMTP_USERNAME}"
SMTP_PASSWORD = "${env.GITHUB_ENV.SMTP_PASSWORD}"
EMAIL_FROM = "${env.GITHUB_ENV.EMAIL_FROM}"
GOOGLE_CLIENT_ID = "${env.GITHUB_ENV.GOOGLE_CLIENT_ID}"
GOOGLE_CLIENT_SECRET = "${env.GITHUB_ENV.GOOGLE_CLIENT_SECRET}"
GOOGLE_CALLBACK_URL = "${env.GITHUB_ENV.GOOGLE_CALLBACK_URL}"
GEMINI_API_KEY = "${env.GITHUB_ENV.GEMINI_API_KEY}"
FIREBASE_TYPE = "${env.GITHUB_ENV.FIREBASE_TYPE}"
FIREBASE_PROJECT_ID = "${env.GITHUB_ENV.FIREBASE_PROJECT_ID}"
FIREBASE_STORAGE_BUCKET = "${env.GITHUB_ENV.FIREBASE_STORAGE_BUCKET}"
FIREBASE_PRIVATE_KEY_ID = "${env.GITHUB_ENV.FIREBASE_PRIVATE_KEY_ID}"
FIREBASE_PRIVATE_KEY = "${env.GITHUB_ENV.FIREBASE_PRI}"
FIREBASE_CLIENT_EMAIL = "${env.GITHUB_ENV.FIREBASE_CLIENT_EMAIL}"
FIREBASE_CLIENT_ID = "${env.GITHUB_ENV.FIREBASE_CLIENT_ID}"
FIREBASE_AUTH_URI = "${env.GITHUB_ENV.FIREBASE_AUTH_URI}"
FIREBASE_TOKEN_URI = "${env.GITHUB_ENV.FIREBASE_TOKEN_URI}"
FIREBASE_AUTH_PROVIDER_X509_CERT_URL = "${env.GITHUB_ENV.FIREBASE_AUTH_PROVIDER_X509_CERT_URL}"
FIREBASE_CLIENT_X509_CERT_URL = "${env.GITHUB_ENV.FIREBASE_CLIENT_X509_CERT_URL}"
FIREBASE_UNIVERSE_DOMAIN = "${env.GITHUB_ENV.FIREBASE_UNIVERSE_DOMAIN}"
FIREBASE_DATABASE_URL = "${env.GITHUB_ENV.FIREBASE_DATABASE_URL}"
RAILWAY_SERVICE_NAME = "${env.GITHUB_ENV.RAILWAY_SERVICE_NAME}"
RAILWAY_TOKEN = "${env.GITHUB_ENV.RAILWAY_TOKEN}"
DOCKER_USERNAME = "${env.GITHUB_ENV.DOCKER_USERNAME}"
DOCKER_PASSWORD = "${env.GITHUB_ENV.DOCKER_PASSWORD}"
}
stages {
stage('Checkout') {
steps {
script {
checkout scmGit(branches: [[name: '*/main']], extensions: [], userRemoteConfigs: [[credentialsId: 'jenkins-demo', url: 'https://github.com/ASE-UIT/congchungonline-be.git']])
}
}
}
stage('Install Dependencies') {
steps {
script {
if (isUnix()) {
// Use shell command for Unix-like systems
sh 'npm install'
} else {
// Use batch command for Windows systems
bat 'npm install'
}
}
}
}
// stage('Run Application') {
// steps {
// script {
// if (isUnix()) {
// sh "export PORT=${PORT} && export JWT_SECRET=${JWT_SECRET} && npm start"
// } else {
// bat "set PORT=${PORT} && set JWT_SECRET=${JWT_SECRET} && npm start"
// }
// }
// }
// }
// stage('Run Tests') {
// steps {
// script {
// if (isUnix()) {
// sh 'npm test'
// } else {
// bat 'npm test'
// }
// }
// }
// }
stage('Build Docker Image') {
steps {
script {
if (isUnix()) {
sh 'docker build -t congchungonline-be .'
} else {
bat 'docker build -t congchungonline-be .'
}
}
}
}
stage('Push Docker Image') {
steps {
script {
if (isUnix()) {
sh 'docker tag congchungonline-be ${env.GITHUB_ENV.DOCKER_USERNAME}/congchungonline-be'
sh 'docker push ${env.GITHUB_ENV.DOCKER_USERNAME}/congchungonline-be'
} else {
bat 'docker tag congchungonline-be %DOCKER_USERNAME%/congchungonline-be'
bat 'docker push %DOCKER_USERNAME%/congchungonline-be'
}
}
}
}
stage('Install Railway') {
steps {
script {
if (isUnix()) {
sh 'npm install -g @railway/cli'
} else {
bat 'npm install -g @railway/cli'
}
}
}
}
stage('Deploy') {
steps {
script {
if (isUnix()) {
sh 'railway up --service ${RAILWAY_SERVICE_NAME}'
} else {
bat 'railway up --service ${RAILWAY_SERVICE_NAME}'
}
}
}
}
}
post {
always {
script {
cleanWs()
}
}
}
}