-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathJenkinsfile
executable file
·166 lines (150 loc) · 6.67 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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/usr/bin/env groovy
//noinspection GroovyAssignabilityCheck
pipeline {
agent { label 'build-agent-01' }
stages {
stage('Set Build Variables') {
steps {
script {
def getProjectVersion = { ->
return sh(
returnStdout: true,
script: 'echo $(node -e "console.log(require(\'./package.json\').version)")'
).replace('\n', '')
}
def getBranchTypeAndName = { String fullBranchName ->
if (fullBranchName in ['develop', 'master']) {
return [fullBranchName, fullBranchName]
}
if (fullBranchName.matches(/^(feature|bugfix)\/[.\d\-\w]+$/)) {
return [fullBranchName.split('/')[0],
fullBranchName.split('/')[1].toLowerCase().replaceAll(/[^.\da-z]/, '.')]
}
if (fullBranchName.matches(/^hotfix\/\d+(\.\d+){1,2}p\d+$/)) {
return fullBranchName.split('/') as List
}
if (fullBranchName.matches(/^release\/\d+(\.\d+){1,2}([ab]\d+)?$/)) {
return fullBranchName.split('/') as List
}
if (fullBranchName.matches(/^PR-\d+-?(merge|head)?$/)) {
return ['PR', fullBranchName.split('-', 2)[1].replaceAll(/-/, '.')]
}
error "Enforcing Gitflow Workflow and SemVer on '${fullBranchName}'. Ha!"
}
def getBuildVersion = { String fullBranchName, buildNumber ->
String projectVersion = getProjectVersion()
def branchTypeAndName = getBranchTypeAndName(fullBranchName)
switch (branchTypeAndName[0]) {
case 'master':
return projectVersion
case 'hotfix':
return "${branchTypeAndName[1]}-rc.${buildNumber}"
case 'develop':
return "${projectVersion}+develop.dev${buildNumber}"
case 'feature':
return "${projectVersion}+feature.${branchTypeAndName[1]}.dev${buildNumber}"
case 'bugfix':
return "${projectVersion}+bugfix.${branchTypeAndName[1]}.dev${buildNumber}"
case 'release':
assert branchTypeAndName[1] == projectVersion
return "${projectVersion}-rc.${buildNumber}"
case 'PR':
return "${projectVersion}+PR.${branchTypeAndName[1]}.${buildNumber}"
default:
error "Oops, we messed up! :("
}
}
def getBuildType = { String fullBranchName ->
switch (getBranchTypeAndName(fullBranchName)[0]) {
case 'master':
return 'latest'
case 'release':
return 'next'
default:
return 'develop'
}
}
env.BUILD_VERSION = getBuildVersion(BRANCH_NAME as String, BUILD_NUMBER)
env.DOCKER_TAG = env.BUILD_VERSION.replace('+', '_')
env.BUILD_TYPE = getBuildType(BRANCH_NAME as String)
env.DOCKER_TAG_ALIAS = env.BUILD_TYPE != 'develop' ? env.BUILD_TYPE : null;
if (env.BUILD_TYPE == 'next') {
sh 'npm version $BUILD_VERSION'
}
stash 'pre_install_git_checkout'
env.VENV_ROOT = "/tmp/xl_auth/${env.BUILD_VERSION}"
sh 'mkdir -p $VENV_ROOT'
}
}
}
stage('Install Dependencies') {
environment {
FLASK_APP = 'autoapp.py'
}
steps {
sh 'scl enable rh-python38 "python3 -m venv $VENV_ROOT/py38venv"'
sh 'scl enable rh-python38 ". $VENV_ROOT/py38venv/bin/activate && python -m pip install -U pip"'
sh 'scl enable rh-python38 "$VENV_ROOT/py38venv/bin/pip --cache-dir ~/.cache/pip38/$EXECUTOR_NUMBER install -r requirements/dev.txt"'
sh 'npm install'
sh 'scl enable rh-python38 ". $VENV_ROOT/py38venv/bin/activate && npm run build"'
}
post {
success {
sh 'scl enable rh-python38 ". $VENV_ROOT/py38venv/bin/activate && \
FLASK_APP=autoapp.py flask translate"'
}
}
}
stage('Run Tests') {
environment {
FLASK_APP = 'autoapp.py'
}
steps {
//noinspection GroovyAssignabilityCheck
parallel(
'ESLint': {
sh 'npm run lint'
},
// 'flake8 (py36)': {
// script {
// try {
// sh 'scl enable rh-python36 ". $VENV_ROOT/py36venv/bin/activate && \
// flask lint" | tee flake8.log && ( exit $PIPESTATUS )'
// }
// catch (Throwable e) {
// junit 'flake8-junit.xml'
// throw e
// }
// }
// },
'pytest (py38)': {
script {
try {
sh 'scl enable rh-python38 ". $VENV_ROOT/py38venv/bin/activate && \
flask test --junit-xml=py38test-junit.xml"'
}
finally {
junit 'py38test-junit.xml'
}
}
}
)
}
}
}
post {
always {
sh 'rm -rf $VENV_ROOT'
deleteDir()
}
success {
echo 'Build succeeded!'
}
failure {
echo 'Build failed :('
}
changed {
echo 'Things are different...'
}
}
}