forked from easysoft/zentaopms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
executable file
·168 lines (158 loc) · 6.23 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
167
168
pipeline {
agent {
kubernetes {
inheritFrom "build-docker code-scan xuanim mysql-server"
}
}
environment {
ZENTAO_VERSION = """${sh(
returnStdout: true,
script: 'cat VERSION'
).trim()}"""
MYSQL_SERVER_HOST = """${sh(
returnStdout: true,
script: 'hostname -I'
).trim()}"""
MYSQL_ROOT_PASSWORD = 'pass4ci'
MIDDLE_IMAGE_REPO = "hub.qc.oop.cc/zentao-ztf"
MIDDLE_IMAGE_TAG = """${sh(
returnStdout: true,
script: 'echo $BUILD_ID-${GIT_COMMIT}'
).trim()}"""
}
stages {
stage("checkout code") {
steps {
echo "checkout code success"
}
}
stage('Sonar Scanner') {
parallel {
stage('SonarQube') {
steps {
container('sonar') {
withSonarQubeEnv('sonarqube') {
sh 'git config --global --add safe.directory $(pwd)'
sh 'sonar-scanner -Dsonar.inclusions=$(git diff --name-only HEAD~1|tr "\\n" ",") -Dsonar.analysis.user=$(git show -s --format=%an)'
}
}
}
post {
success {
container('xuanimbot') {
sh 'git config --global --add safe.directory $(pwd)'
sh '/usr/local/bin/xuanimbot --users "$(git show -s --format=%an)" --title "sonar scanner" --url "https://sonar.qc.oop.cc/dashboard?id=zentaopms&branch=${GIT_BRANCH}" --content "sonar scanner success" --debug --custom'
}
}
failure {
container('xuanimbot') {
sh 'git config --global --add safe.directory $(pwd)'
sh '/usr/local/bin/xuanimbot --users "$(git show -s --format=%an)" --title "sonar scanner" --url "https://sonar.qc.oop.cc/dashboard?id=zentaopms&branch=${GIT_BRANCH}" --content "sonar scanner failure" --debug --custom'
}
}
}
}
stage('Build Image') {
steps {
container('docker') {
sh 'docker build --pull . -f Dockerfile.test --build-arg VERSION=${ZENTAO_VERSION} --build-arg MIRROR=true --build-arg MYSQL_HOST=${MYSQL_SERVER_HOST} --build-arg MYSQL_PASSWORD=${MYSQL_ROOT_PASSWORD} -t ${MIDDLE_IMAGE_REPO}:${MIDDLE_IMAGE_TAG}'
sh 'docker push ${MIDDLE_IMAGE_REPO}:${MIDDLE_IMAGE_TAG}'
}
}
post {
success {
echo 'build image success'
}
failure {
container('xuanimbot') {
sh 'git config --global --add safe.directory $(pwd)'
sh '/usr/local/bin/xuanimbot --users "$(git show -s --format=%an)" --title "build image" --url "${RUN_DISPLAY_URL}" --content "Build unit test image failure" --debug --custom'
}
}
}
}
}
}
stage('Unit Test'){
stages{
stage('Init') {
agent {
kubernetes {
inheritFrom "xuanim"
containerTemplate {
name "zentao"
image "${MIDDLE_IMAGE_REPO}:${MIDDLE_IMAGE_TAG}"
command "sleep"
args "99d"
}
}
}
options { skipDefaultCheckout() }
steps {
container('zentao') {
sh 'initdb.php ; /apps/zentao/test/ztest init'
}
}
post {
success {
sh 'echo "stage unit init success"'
}
failure {
container('xuanimbot') {
sh 'git config --global --add safe.directory $(pwd)'
sh '/usr/local/bin/xuanimbot --users "$(git show -s --format=%an)" --title "unittest init" --url "${RUN_DISPLAY_URL}" --content "Unit test database initialization failed" --debug --custom'
}
}
}
}
stage('Run') {
matrix {
agent {
kubernetes {
inheritFrom "xuanim"
containerTemplate {
name "zentao"
image "${MIDDLE_IMAGE_REPO}:${MIDDLE_IMAGE_TAG}"
command "sleep"
args "99d"
}
}
}
options { skipDefaultCheckout() }
axes {
axis {
name "SEQUENCE"
values "P1", "P2", "P3", "P4", "P5", "P6", "P7"
}
}
stages {
stage("Run") {
steps {
container('zentao') {
sh 'initdb.php config'
sh '/apps/zentao/test/ztest extract ; /apps/zentao/test/ztest ${SEQUENCE} | tee /apps/zentao/test/${SEQUENCE}.log'
sh 'pipeline-unittest.sh /apps/zentao/test/${SEQUENCE}.log'
}
}
}
}
}
post{
success{
container('xuanimbot') {
sh 'git config --global --add safe.directory /home/jenkins/agent/workspace/pangu_pangu_xuanimbot_master'
sh '/usr/local/bin/xuanimbot --users "$(git show -s --format=%an)" --title "unittest" --url "${RUN_DISPLAY_URL}" --content "Unit test passed" --debug --custom'
}
}
failure{
container('xuanimbot') {
sh 'git config --global --add safe.directory $(pwd)'
sh '/usr/local/bin/xuanimbot --users "$(git show -s --format=%an)" --title "unittest" --url "${RUN_DISPLAY_URL}" --content "Unit test failed" --debug --custom'
}
}
}
}//End unittest
}
}
} // End Root Stages
} // End pipeline