Repository navigation
Expand file tree
/
Copy pathdasd.gr
More file actions
116 lines (104 loc) · 4.13 KB
/
Copy pathdasd.gr
File metadata and controls
116 lines (104 loc) · 4.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
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
def sendSlackNotification() {
def COLOR_MAP = [
'SUCCESS': 'good',
'FAILURE': 'danger',
]
if (MSG != '') {
env.CHANGES = MSG
} else {
env.CHANGES = getChanges()
}
wrap([$class: 'BuildUser']) {
mattermostSend(
channel: 'backups',
color: COLOR_MAP[currentBuild.currentResult],
message: "**${currentBuild.currentResult}:** Job [${env.JOB_NAME} ${env.BUILD_NUMBER}](${env.BUILD_URL}) by ${env.BUILD_USER}, [check logs](${env.BUILD_URL}console)\n**Environment**: ${env.ENVIRONMENT}\n**Branch**: ${params.COMMIT}\n\n**Changelog:**\n\n${env.CHANGES}"
)
}
}
def triggeredSlackNotification() {
if (MSG != '') {
env.CHANGES = MSG
} else {
env.CHANGES = getChanges()
}
wrap([$class: 'BuildUser']) {
mattermostSend(
color: 'silver',
channel: 'backups',
message: "**TRIGGERED:** Job [${env.JOB_NAME} ${env.BUILD_NUMBER}](${env.BUILD_URL}) by ${env.BUILD_USER}, [check logs](${env.BUILD_URL}console)\n**Environment**: ${env.ENVIRONMENT}\n**Branch**: ${params.COMMIT}\n\n**Changelog:**\n\n${env.CHANGES}"
)
}
}
def getChanges() {
MAX_MSG_LEN = 100
def changes = ""
echo "Gathering SCM changes"
def changeLogSets = currentBuild.rawBuild.changeSets
changeLogSets.each { def changeLogSet ->
def entries = changeLogSet.items
entries.each { def entry ->
truncated_msg = entry.msg.take(MAX_MSG_LEN)
changes += " - $truncated_msg [$entry.author]\n"
}
}
if (!changes) {
changes = " - No new changes"
}
return changes
}
node {
def remote = [:]
remote.name = "sk-engineering-dev-frontend"
remote.host = "45.8.250.8"
remote.port = 22
remote.allowAnyHosts = true
env.ENVIRONMENT = 'DEV'
stage("Installation and preparations") {
catchError {
docker.image('oven/bun').inside() {
stage('Fetch latest changes') {
checkout([$class: 'GitSCM',
branches: [[name: params.COMMIT]],
doGenerateSubmoduleConfigurations: false,
extensions: [],
gitTool: 'Default',
submoduleCfg: [],
userRemoteConfigs: [[credentialsId: 'sk-engineering-github-frontend-ssh-key', url: 'git@github.com:LighTechLLC/sk-engineering-frontend.git']]
])
triggeredSlackNotification()
}
stage('Install npm packages') {
sh 'rm -rf node_modules'
sh 'bun install'
}
stage('Generate types and routes') {
sh 'rm -rf src/gen'
sh 'bun run generate:kubb'
sh 'bun run postgenerate:kubb'
sh 'bun run generate:routes'
}
stage('Build') {
sh 'bun run build'
sh 'ls -l dist'
sh 'tar -czf dist.tar.gz dist/'
}
stage('Node modules deletion') {
sh 'rm -rf node_modules'
}
stage('Deployment') {
withCredentials([sshUserPrivateKey(credentialsId: 'sk-engineering-dev-vds-ssh-access', keyFileVariable: 'identity', usernameVariable: 'userName')]) {
remote.user = 'jenkins'
remote.identityFile = identity
sshPut remote: remote, from: 'dist.tar.gz', into: '/tmp/'
sshCommand remote: remote, command: 'cd /tmp/ && tar -xzf dist.tar.gz && rm dist.tar.gz'
sshCommand remote: remote, command: "rm -rf /var/www/frontend/${env.ENVIRONMENT.toLowerCase()}"
sshCommand remote: remote, command: "mv /tmp/dist/ /var/www/frontend/${env.ENVIRONMENT.toLowerCase()}"
sshCommand remote: remote, command: 'rm -rf /tmp/dist/'
}
}
}
}
sendSlackNotification()
}
}