-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
86 lines (77 loc) · 2.13 KB
/
Jenkinsfile
File metadata and controls
86 lines (77 loc) · 2.13 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
pipeline {
agent {
label 'slave'
}
environment {
DEPLOY_SERVER = 'ubuntu@3.124.192.157'
BOOKS_SERVICE_DIR = '/home/ubuntu/eBooks-API'
GIT_REPO = 'git@github.com:Zaiidmo/eBooks-API.git'
WORKSPACE = "${JENKINS_HOME}/workspace/books-service-pipeline"
NODE_OPTIONS = '--max_old_space_size=4096'
}
tools {
nodejs 'Node-20.9.0'
}
stages {
stage('Cleanup Workspace') {
steps {
cleanWs()
}
}
stage('Checkout') {
steps {
git branch: 'master',
url: "${GIT_REPO}"
}
}
stage('Install Dependencies') {
steps {
sh '''
npm cache clean --force
npm install -g @nestjs/cli
npm install
'''
}
}
stage('Test') {
steps {
sh 'npm test'
}
}
stage('Build') {
steps {
sh 'npm run build'
}
}
stage('Deploy to Books-Service') {
steps {
sshagent(['jenkins-slave-key']) {
script {
sh """
ssh -o StrictHostKeyChecking=no ${DEPLOY_SERVER} "
cd ${BOOKS_SERVICE_DIR} && \
GIT_SSH_COMMAND='ssh -i ~/.ssh/jenkins_github_key -o StrictHostKeyChecking=no' git pull origin master && \
npm install && \
npm run build && \
pm2 delete all && \
pm2 start dist/src/main.js --name eBooks-API
"
"""
}
}
}
}
}
post {
always {
echo 'Pipeline finished'
cleanWs()
}
success {
echo 'Pipeline succeeded!'
}
failure {
echo 'Pipeline failed!'
}
}
}