-
Notifications
You must be signed in to change notification settings - Fork 6
/
Jenkinsfile
88 lines (80 loc) · 2.81 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
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env groovy
@Library('ZomisJenkins')
import net.zomis.jenkins.Duga
pipeline {
agent any
stages {
stage('Prepare') {
steps {
checkout scm
}
}
stage('Validate branch name') {
when {
expression {
return !(env.GIT_BRANCH ==~ /\w+(\/\w+)?[\w\d\-]+/)
}
}
steps {
error("Invalid branch name")
}
}
stage('Environment Vars') {
steps {
script {
sh 'rm -f .env.local'
def timestamp = new Date().format("yyyy-MM-dd HH:mm:ss", TimeZone.getTimeZone('UTC'))
sh "echo 'VUE_APP_BUILD_TIME=$timestamp' >> .env.local"
sh "echo 'VUE_APP_BUILD_NUMBER=$env.BUILD_NUMBER' >> .env.local"
sh "echo 'VUE_APP_GIT_COMMIT=$env.GIT_COMMIT' >> .env.local"
sh "echo 'VUE_APP_GIT_BRANCH=$env.GIT_BRANCH' >> .env.local"
sh 'cat .env.local'
}
}
}
stage('Build') {
steps {
sh 'mkdir -p src/kotlin'
sh 'cp /home/zomis/jenkins/mfe/minesweeper-core.js src/kotlin/minesweeper-core.js'
sh 'npm install'
sh 'npm run build'
}
}
stage('Docker') {
steps {
sh "rm -rf /home/zomis/jenkins/mfe/client/$env.GIT_BRANCH"
script {
def path = "/home/zomis/jenkins/mfe/client/$env.GIT_BRANCH"
if (env.GIT_BRANCH == 'main') {
path = '/home/zomis/jenkins/mfe/client'
}
// Copy files
sh "mkdir -p $path"
sh "cp -r \$(pwd)/dist/* $path"
writeFile file: path + '/version.json', text: "$env.BUILD_NUMBER"
// The client is open source, let them be, but here we could move *.map files outside of client so that they are not visible
// sh "mv $path/js/*.map $path../mapfiles/" //
// Start container if needed
def runningContainers = sh(script: 'docker ps -q -f "name=mfe_client"', returnStdout: true).trim()
if (runningContainers.isEmpty()) {
sh 'docker run -d --rm --name mfe_client -v /home/zomis/jenkins/mfe/client:/usr/share/nginx/html:ro -p 64637:80 nginx'
}
}
}
}
}
post {
always {
junit allowEmptyResults: true, testResults: '**/build/test-results/junit-platform/TEST-*.xml'
}
success {
zpost(0)
}
unstable {
zpost(1)
}
failure {
zpost(2)
}
}
}