-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
72 lines (72 loc) · 2.61 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
pipeline {
agent any
tools {
dotnetsdk 'dotnet-sdk-8.0'
}
environment {
PATH = "$PATH:/root/.dotnet/tools"
}
stages {
stage('Setup Environment') {
steps {
echo 'Installing necessary packages...'
sh 'apt-get update && apt-get install -y libicu-dev'
}
}
stage('Checkout') {
steps {
git branch: 'main',
credentialsId: 'deploy',
url: '[email protected]:RommensArne/TestNet-repo.git'
}
}
stage('Restore Dependencies') {
steps {
sh 'dotnet restore'
}
}
stage('Install dotnet ef Tool') {
steps {
echo 'Installing dotnet-ef tool...'
sh 'dotnet tool install --global dotnet-ef'
}
}
stage('Apply Migrations') {
steps {
echo 'Applying database migrations...'
sh 'dotnet ef database update --startup-project Rise.Server --project Rise.Persistence'
}
}
stage('Publish Application') {
steps {
echo 'Publishing the application...'
sh 'dotnet publish Rise.Server/Rise.Server.csproj -c Release -o ./publish/server'
sh 'dotnet publish Rise.Client/Rise.Client.csproj -c Release -o ./publish/client'
}
}
stage('Deploy to AppServer') {
steps {
echo 'Preparing and copying files to AppServer...'
withCredentials([sshUserPrivateKey(credentialsId: 'appserver', keyFileVariable: 'SSH_KEY')]) {
sh """
ssh -i $SSH_KEY -o StrictHostKeyChecking=no [email protected] '
sudo mkdir -p /home/server /home/client &&
sudo chown -R vagrant:vagrant /home/server /home/client &&
sudo chmod -R 755 /home/server /home/client
'
scp -i $SSH_KEY -o StrictHostKeyChecking=no -r ./publish/server/* [email protected]:/home/server/
scp -i $SSH_KEY -o StrictHostKeyChecking=no -r ./publish/client/* [email protected]:/home/client/
"""
}
}
}
}
post {
success {
echo 'Pipeline completed successfully! Database created successfully and application published!'
}
failure {
echo 'Pipeline execution failed. Database creation failed.'
}
}
}