-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile-master
69 lines (60 loc) · 2.05 KB
/
Jenkinsfile-master
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
pipeline {
agent any
stages {
stage('Checkout') {
steps {
sh 'echo "Checking out..."'
checkout scm
}
}
stage('Backend Build and Test') {
steps {
dir('backend') {
// Change to the backend directory
sh 'echo "Building Backend..."'
sh 'npm install'
sh 'echo "Testing Backend..."'
sh 'npm test'
}
}
}
stage('Frontend Build and Test') {
steps {
dir('frontend') {
// Change to the frontend directory
sh 'echo "Building Frontend..."'
sh 'npm install'
sh 'echo "Testing Frontend..."'
sh 'npm test'
}
}
}
stage('Database Migration') {
steps {
sh 'echo "Migrating Database..."'
// maybe use 'mongorestore' ?
}
}
stage('Deploy') {
steps {
sh 'echo "Deploying..."'
// Define EC2 instance details
def ec2Instance = 'your-ec2-instance-ip' // or hostname
def ec2User = 'ec2-user' // or the SSH user you use to connect to the instance
def sshKey = 'your-ssh-key' // the private key file to use for authentication
def appDir = '/path/to/your/app/directory'
sh "scp -i ${sshKey} -r your-app-directory/* ${ec2User}@${ec2Instance}:${appDir}"
sh "ssh -i ${sshKey} ${ec2User}@${ec2Instance} 'cd ${appDir} && npm install'"
sh "ssh -i ${sshKey} ${ec2User}@${ec2Instance} 'cd ${appDir} && pm2 restart your-app.js'"
}
}
}
post {
success {
sh 'echo "Pipeline succeeded :)"'
}
failure {
sh 'echo "Pipeline failed :("'
}
}
}