-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
76 lines (72 loc) · 2.2 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
pipeline {
agent any
tools {
nodejs 'node'
}
environment {
NODE_ENV = 'development'
}
stages {
stage('Checkout') {
steps {
checkout([$class: 'GitSCM', branches: [[name: '*/main']], userRemoteConfigs: [[url: 'https://github.com/team-1-genics-2024/BE.git']]])
}
}
stage('Load Env File') {
steps {
// Mengambil secret file .env dari Jenkins Credentials dan memuatnya
withCredentials([file(credentialsId: 'env-file', variable: 'ENV_FILE')]) {
// Menyalin secret file dari Jenkins credentials ke dalam workspace sebagai .env
sh 'cp $ENV_FILE .env'
}
}
}
stage('Setup log dir') {
steps {
sh 'mkdir -p logs'
sh 'touch logs/prisma.log'
sh 'touch logs/redis.log'
}
}
stage('install dependencies') {
steps {
sh 'npm install'
}
}
stage('Run Tests') {
steps {
sh 'echo "Running tests..."'
}
}
stage('Build') {
steps {
sh 'npm run build'
}
}
stage('Deploy and Build on Server') {
steps {
// Mengambil IP server dari Jenkins Credentials
withCredentials([string(credentialsId: 'DEV_SERVER_IP', variable: 'DEV_IP')]) {
// Gunakan SSH Agent untuk koneksi ke server
sshagent(['SERVER_SSH_KEY_ID']) {
// Jalankan command di development server
sh '''
ssh -o StrictHostKeyChecking=no yuta@$DEV_IP "bash -c 'source ~/.nvm/nvm.sh && nvm use --lts && cd BE && git pull origin main && npm install && npm run build && npm run deploy:dev'"
'''
}
}
}
}
}
post {
always {
sh 'rm -f .env'
}
success {
echo 'Build success!'
}
failure {
echo 'Build failed!'
}
}
}