Jenkinsfile 15.6 KB
Newer Older
L
liuyq-617 已提交
1
import hudson.model.Result
L
liuyq-617 已提交
2
import hudson.model.*;
L
liuyq-617 已提交
3
import jenkins.model.CauseOfInterruption
4 5 6
node {
}

L
liuyq-617 已提交
7 8 9
def skipbuild = 0
def win_stop = 0
def scope = []
L
liuyq-617 已提交
10
def mod = [0,1,2,3,4]
L
liuyq-617 已提交
11

L
recover  
liuyq-617 已提交
12 13 14 15 16
def abortPreviousBuilds() {
  def currentJobName = env.JOB_NAME
  def currentBuildNumber = env.BUILD_NUMBER.toInteger()
  def jobs = Jenkins.instance.getItemByFullName(currentJobName)
  def builds = jobs.getBuilds()
17

L
recover  
liuyq-617 已提交
18 19 20 21
  for (build in builds) {
    if (!build.isBuilding()) {
      continue;
    }
L
liuyq-617 已提交
22

L
recover  
liuyq-617 已提交
23 24 25 26 27 28 29 30 31 32 33 34 35 36
    if (currentBuildNumber == build.getNumber().toInteger()) {
      continue;
    }

    build.doKill()    //doTerm(),doKill(),doTerm()
  }
}
//  abort previous build
abortPreviousBuilds()
def abort_previous(){
  def buildNumber = env.BUILD_NUMBER as int
  if (buildNumber > 1) milestone(buildNumber - 1)
  milestone(buildNumber)
}
37
def pre_test(){
L
liuyq-617 已提交
38
    sh'hostname'
L
liuyq-617 已提交
39 40 41
    sh '''
    sudo rmtaos || echo "taosd has not installed"
    '''
L
liuyq-617 已提交
42
    sh '''
43 44
    kill -9 $(pidof taosd) ||echo "no taosd running"
    kill -9 $(pidof taosadapter) ||echo "no taosadapter running"
L
fix  
liuyq-617 已提交
45
    killall -9 gdb || echo "no gdb running"
L
liuyq-617 已提交
46
    killall -9 python3.8 || echo "no python program running"
47 48
    cd ${WKC}
    git reset --hard HEAD~10 >/dev/null
L
fix  
liuyq-617 已提交
49 50 51
    '''
    script {
      if (env.CHANGE_TARGET == 'master') {
L
fix  
liuyq-617 已提交
52
        sh '''
53 54
        cd ${WKC}
        git checkout master
L
fix  
liuyq-617 已提交
55
        '''
L
fix  
liuyq-617 已提交
56
        }
L
liuyq-617 已提交
57
      else if(env.CHANGE_TARGET == '2.4'){
L
fix  
liuyq-617 已提交
58
        sh '''
59
        cd ${WKC}
L
liuyq-617 已提交
60
        git checkout 2.4
L
fix  
liuyq-617 已提交
61
        '''
62
      }
63 64
      else{
        sh '''
65 66
        cd ${WKC}
        git checkout develop
67 68
        '''
      }
L
fix  
liuyq-617 已提交
69 70
    }
    sh'''
L
fix  
liuyq-617 已提交
71
    cd ${WKC}
72
    git remote prune origin
73 74
    [ -f src/connector/grafanaplugin/README.md ] && rm -f src/connector/grafanaplugin/README.md > /dev/null || echo "failed to remove grafanaplugin README.md"
    git pull >/dev/null
L
liuyq-617 已提交
75
    git fetch origin +refs/pull/${CHANGE_ID}/merge
76
    git checkout -qf FETCH_HEAD
77
    git clean -dfx
78
    git submodule update --init --recursive
79 80
    cd ${WK}
    git reset --hard HEAD~10
L
fix  
liuyq-617 已提交
81
    '''
82 83 84 85 86 87 88
    script {
      if (env.CHANGE_TARGET == 'master') {
        sh '''
        cd ${WK}
        git checkout master
        '''
        }
L
liuyq-617 已提交
89
      else if(env.CHANGE_TARGET == '2.4'){
90 91
        sh '''
        cd ${WK}
L
liuyq-617 已提交
92
        git checkout 2.4
93
        '''
94
      }
95 96 97 98 99
      else{
        sh '''
        cd ${WK}
        git checkout develop
        '''
100
      }
101
    }
L
fix  
liuyq-617 已提交
102
    sh '''
103
    cd ${WK}
104 105
    git pull >/dev/null

106 107
    export TZ=Asia/Harbin
    date
108
    git clean -dfx
109 110
    mkdir debug
    cd debug
111
    cmake .. -DBUILD_HTTP=false -DBUILD_TOOLS=true > /dev/null
112 113 114
    make > /dev/null
    make install > /dev/null
    cd ${WKC}/tests
115
    pip3 install ${WKC}/src/connector/python/
L
update  
liuyq-617 已提交
116 117 118 119 120 121
    '''
    return 1
}
def pre_test_noinstall(){
    sh'hostname'
    sh'''
122 123
    cd ${WKC}
    git reset --hard HEAD~10 >/dev/null
L
update  
liuyq-617 已提交
124 125 126 127
    '''
    script {
      if (env.CHANGE_TARGET == 'master') {
        sh '''
128 129
        cd ${WKC}
        git checkout master
L
update  
liuyq-617 已提交
130 131
        '''
        }
L
liuyq-617 已提交
132
      else if(env.CHANGE_TARGET == '2.4'){
L
update  
liuyq-617 已提交
133
        sh '''
134
        cd ${WKC}
L
liuyq-617 已提交
135
        git checkout 2.4
L
update  
liuyq-617 已提交
136
        '''
137
      }
L
update  
liuyq-617 已提交
138 139
      else{
        sh '''
140 141
        cd ${WKC}
        git checkout develop
L
update  
liuyq-617 已提交
142 143 144 145 146
        '''
      }
    }
    sh'''
    cd ${WKC}
147
    git remote prune origin
148 149
    [ -f src/connector/grafanaplugin/README.md ] && rm -f src/connector/grafanaplugin/README.md > /dev/null || echo "failed to remove grafanaplugin README.md"
    git pull >/dev/null
L
update  
liuyq-617 已提交
150 151
    git fetch origin +refs/pull/${CHANGE_ID}/merge
    git checkout -qf FETCH_HEAD
152
    git clean -dfx
L
update  
liuyq-617 已提交
153
    git submodule update --init --recursive
154 155
    cd ${WK}
    git reset --hard HEAD~10
L
update  
liuyq-617 已提交
156
    '''
157 158 159 160 161 162 163
    script {
      if (env.CHANGE_TARGET == 'master') {
        sh '''
        cd ${WK}
        git checkout master
        '''
        }
L
liuyq-617 已提交
164
      else if(env.CHANGE_TARGET == '2.4'){
165 166
        sh '''
        cd ${WK}
L
liuyq-617 已提交
167
        git checkout 2.4
168
        '''
169
      }
170 171 172 173 174
      else{
        sh '''
        cd ${WK}
        git checkout develop
        '''
175
      }
176
    }
L
update  
liuyq-617 已提交
177
    sh '''
178
    cd ${WK}
179 180
    git pull >/dev/null

L
update  
liuyq-617 已提交
181 182
    export TZ=Asia/Harbin
    date
183
    git clean -dfx
L
update  
liuyq-617 已提交
184 185
    mkdir debug
    cd debug
186
    cmake .. -DBUILD_HTTP=false -DBUILD_TOOLS=false > /dev/null
187
    make
L
liuyq-617 已提交
188
    '''
189 190
    return 1
}
L
liuyq-617 已提交
191 192 193
def pre_test_mac(){
    sh'hostname'
    sh'''
194 195
    cd ${WKC}
    git reset --hard HEAD~10 >/dev/null
L
liuyq-617 已提交
196 197 198 199
    '''
    script {
      if (env.CHANGE_TARGET == 'master') {
        sh '''
200 201
        cd ${WKC}
        git checkout master
L
liuyq-617 已提交
202 203
        '''
        }
L
liuyq-617 已提交
204
      else if(env.CHANGE_TARGET == '2.4'){
L
liuyq-617 已提交
205
        sh '''
206
        cd ${WKC}
L
liuyq-617 已提交
207
        git checkout 2.4
L
liuyq-617 已提交
208
        '''
209
      }
L
liuyq-617 已提交
210 211
      else{
        sh '''
212 213
        cd ${WKC}
        git checkout develop
L
liuyq-617 已提交
214 215 216 217 218
        '''
      }
    }
    sh'''
    cd ${WKC}
219
    git remote prune origin
220 221
    [ -f src/connector/grafanaplugin/README.md ] && rm -f src/connector/grafanaplugin/README.md > /dev/null || echo "failed to remove grafanaplugin README.md"
    git pull >/dev/null
L
liuyq-617 已提交
222 223
    git fetch origin +refs/pull/${CHANGE_ID}/merge
    git checkout -qf FETCH_HEAD
224
    git clean -dfx
L
liuyq-617 已提交
225
    git submodule update --init --recursive
226 227
    cd ${WK}
    git reset --hard HEAD~10
L
liuyq-617 已提交
228
    '''
229 230 231 232 233 234 235
    script {
      if (env.CHANGE_TARGET == 'master') {
        sh '''
        cd ${WK}
        git checkout master
        '''
        }
L
liuyq-617 已提交
236
      else if(env.CHANGE_TARGET == '2.4'){
237 238
        sh '''
        cd ${WK}
L
liuyq-617 已提交
239
        git checkout 2.4
240
        '''
241
      }
242 243 244 245 246
      else{
        sh '''
        cd ${WK}
        git checkout develop
        '''
247
      }
248
    }
L
liuyq-617 已提交
249
    sh '''
250
    cd ${WK}
251 252
    git pull >/dev/null

L
liuyq-617 已提交
253 254
    export TZ=Asia/Harbin
    date
255
    git clean -dfx
L
liuyq-617 已提交
256 257
    mkdir debug
    cd debug
258
    cmake .. -DBUILD_TOOLS=false > /dev/null
259 260
    go env -w GOPROXY=https://goproxy.cn,direct
    go env -w GO111MODULE=on
L
liuyq-617 已提交
261 262 263 264
    cmake --build .
    '''
    return 1
}
265 266
def pre_test_win(){
    bat '''
L
update  
liuyq-617 已提交
267
    taskkill /f /t /im python.exe
268 269
    cd C:\\
    rd /s /Q C:\\TDengine
270 271 272
    cd C:\\workspace\\TDinternal
    rd /s /Q C:\\workspace\\TDinternal\\debug
    cd C:\\workspace\\TDinternal\\community
273
    git reset --hard HEAD~10
274 275 276 277
    '''
    script {
      if (env.CHANGE_TARGET == 'master') {
        bat '''
278 279
        cd C:\\workspace\\TDinternal\\community
        git checkout master
280 281
        '''
        }
L
liuyq-617 已提交
282
      else if(env.CHANGE_TARGET == '2.4'){
283
        bat '''
284
        cd C:\\workspace\\TDinternal\\community
L
liuyq-617 已提交
285
        git checkout 2.4
286
        '''
287
      }
288 289
      else{
        bat '''
290 291
        cd C:\\workspace\\TDinternal\\community
        git checkout develop
292 293 294 295 296
        '''
      }
    }
    bat'''
    cd C:\\workspace\\TDinternal\\community
297 298
    git remote prune origin
    git pull
L
liuyq-617 已提交
299
    git fetch origin +refs/pull/%CHANGE_ID%/merge
300
    git checkout -qf FETCH_HEAD
301
    git clean -dfx
302
    git submodule update --init --recursive
303 304
    cd C:\\workspace\\TDinternal
    git reset --hard HEAD~10
305
    '''
306 307 308 309 310 311 312
    script {
      if (env.CHANGE_TARGET == 'master') {
        bat '''
        cd C:\\workspace\\TDinternal
        git checkout master
        '''
        }
L
liuyq-617 已提交
313
      else if(env.CHANGE_TARGET == '2.4'){
314 315
        bat '''
        cd C:\\workspace\\TDinternal
L
liuyq-617 已提交
316
        git checkout 2.4
317
        '''
318
      }
319 320 321 322 323
      else{
        bat '''
        cd C:\\workspace\\TDinternal
        git checkout develop
        '''
324
      }
325
    }
326 327
    bat '''
    cd C:\\workspace\\TDinternal
328
    git pull
329

330
    date
331
    git clean -dfx
332 333
    mkdir debug
    cd debug
L
liuyq-617 已提交
334
    call "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Auxiliary\\Build\\vcvarsall.bat" amd64
335
    cmake ../ -G "NMake Makefiles"
L
liuyq-617 已提交
336
    set CL=/MP nmake nmake || exit 8
L
update  
liuyq-617 已提交
337
    nmake install || exit 8
L
liuyq-617 已提交
338
    xcopy /e/y/i/f C:\\workspace\\TDinternal\\debug\\build\\lib\\taos.dll C:\\Windows\\System32 || exit 8
339 340
    cd C:\\workspace\\TDinternal\\community\\src\\connector\\python
    python -m pip install .
341

342 343 344
    '''
    return 1
}
Y
Yiqing Liu 已提交
345
pipeline {
L
liuyq-617 已提交
346
  agent none
347
  options { skipDefaultCheckout() }
L
liuyq-617 已提交
348 349 350 351
  environment{
      WK = '/var/lib/jenkins/workspace/TDinternal'
      WKC= '/var/lib/jenkins/workspace/TDinternal/community'
  }
Y
Yiqing Liu 已提交
352
  stages {
L
change  
liuyq-617 已提交
353
      stage('pre_build'){
L
liuyq-617 已提交
354
          agent{label 'catalina'}
355
          options { skipDefaultCheckout() }
L
liuyq-617 已提交
356 357 358
          when {
              changeRequest()
          }
359
          steps {
L
change  
liuyq-617 已提交
360 361 362
            script{
              abort_previous()
              abortPreviousBuilds()
L
liuyq-617 已提交
363
              println env.CHANGE_BRANCH
L
liuyq-617 已提交
364
              if(env.CHANGE_FORK){
365
                scope = ['connector','query','insert','other','tools','taosAdapter']
L
liuyq-617 已提交
366 367 368
              }
              else{
                sh'''
L
liuyq-617 已提交
369
                  cd ${WKC}
370
                  git reset --hard HEAD~10
L
liuyq-617 已提交
371 372 373
                  git fetch
                  git checkout ${CHANGE_BRANCH}
                  git pull
L
liuyq-617 已提交
374
                '''
L
liuyq-617 已提交
375 376 377
                dir('/var/lib/jenkins/workspace/TDinternal/community'){
                  gitlog = sh(script: "git log -1 --pretty=%B ", returnStdout:true)
                  println gitlog
L
liuyq-617 已提交
378
                  if (!(gitlog =~ /\((.*?)\)/)){
L
liuyq-617 已提交
379 380 381
                    autoCancelled = true
                    error('Aborting the build.')
                  }
L
liuyq-617 已提交
382
                  temp = (gitlog =~ /\((.*?)\)/)
L
liuyq-617 已提交
383 384
                  temp = temp[0].remove(1)
                  scope = temp.split(",")
L
liuyq-617 已提交
385
                  Collections.shuffle mod
L
liuyq-617 已提交
386
                }
387

L
liuyq-617 已提交
388 389
              }
            }    
390 391
          }
      }
L
change  
liuyq-617 已提交
392
      stage('Parallel test stage') {
L
liuyq-617 已提交
393
        //only build pr
394
        options { skipDefaultCheckout() }
L
liuyq-617 已提交
395
        when {
L
liuyq-617 已提交
396
          allOf{
L
liuyq-617 已提交
397
              changeRequest()
398
              not{ expression { env.CHANGE_BRANCH =~ /docs\// }}
L
liuyq-617 已提交
399
            }
L
liuyq-617 已提交
400
          }
Y
Yiqing Liu 已提交
401
      parallel {
L
liuyq-617 已提交
402
        stage('python_1') {
L
liuyq-617 已提交
403
          agent{label " slave1 || slave6 || slave11 || slave16 "}
L
liuyq-617 已提交
404
          steps {
405
            pre_test()
L
liuyq-617 已提交
406
            timeout(time: 55, unit: 'MINUTES'){
L
liuyq-617 已提交
407 408 409 410 411
              script{
                scope.each {
                  sh """
                    date
                    cd ${WKC}/tests
L
liuyq-617 已提交
412
                    ./test-CI.sh ${it} 5 ${mod[0]}
L
liuyq-617 已提交
413 414 415 416
                    date"""
                  }
                }
            }            
L
liuyq-617 已提交
417 418
          }
        }
L
liuyq-617 已提交
419 420
        stage('python_2') {
          agent{label " slave2 || slave7 || slave12 || slave17 "}
L
liuyq-617 已提交
421 422
          steps {
            pre_test()
L
liuyq-617 已提交
423
            timeout(time: 55, unit: 'MINUTES'){
L
liuyq-617 已提交
424 425 426 427 428
                 script{
                  scope.each {
                    sh """
                      date
                      cd ${WKC}/tests
L
liuyq-617 已提交
429
                      ./test-CI.sh ${it} 5 ${mod[1]} 
L
liuyq-617 已提交
430 431 432
                      date"""
                    }
                }
L
liuyq-617 已提交
433
            }
L
liuyq-617 已提交
434 435
          }
        }
L
liuyq-617 已提交
436 437
        stage('python_3') {
          agent{label " slave3 || slave8 || slave13 ||slave18 "}
438
          steps {
439
            timeout(time: 105, unit: 'MINUTES'){
L
liuyq-617 已提交
440
              pre_test()
L
liuyq-617 已提交
441 442 443 444 445
              script{
              scope.each {
                sh """
                  date
                  cd ${WKC}/tests
L
liuyq-617 已提交
446
                  ./test-CI.sh ${it} 5 ${mod[2]}
L
liuyq-617 已提交
447 448
                  date"""
                }
449
              }
L
liuyq-617 已提交
450
            }
Y
Yiqing Liu 已提交
451 452
          }
        }
L
liuyq-617 已提交
453 454
        stage('python_4') {
          agent{label " slave4 || slave9 || slave14 || slave19 "}
455 456
          steps {
            timeout(time: 55, unit: 'MINUTES'){
L
liuyq-617 已提交
457
              pre_test()
L
liuyq-617 已提交
458 459 460 461 462
              script{
              scope.each {
                sh """
                  date
                  cd ${WKC}/tests
L
liuyq-617 已提交
463
                  ./test-CI.sh ${it} 5 ${mod[3]}
L
liuyq-617 已提交
464 465 466 467
                  date"""
                }
              }
          
L
liuyq-617 已提交
468 469 470
            }
          }
        }
L
liuyq-617 已提交
471 472
        stage('python_5') {
          agent{label " slave5 || slave10 || slave15 || slave20 "}
473 474
          steps {
            timeout(time: 55, unit: 'MINUTES'){
L
liuyq-617 已提交
475
              pre_test()
L
liuyq-617 已提交
476 477 478 479 480
              script{
              scope.each {
                sh """
                  date
                  cd ${WKC}/tests
L
liuyq-617 已提交
481
                  ./test-CI.sh ${it} 5 ${mod[4]}
L
liuyq-617 已提交
482 483 484 485
                  date"""
                }
              }
          
L
liuyq-617 已提交
486 487
            }
          }
488
        }
L
liuyq-617 已提交
489 490
        stage('Mac_build') {
          agent{label " catalina "}
491 492
          steps {
              pre_test_mac()
L
liuyq-617 已提交
493 494
            }
        }
Y
Yiqing Liu 已提交
495 496
    }
  }
L
liuyq-617 已提交
497
  }
498
  post {
499 500
        success {
            emailext (
501 502
                subject: "PR-result: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' SUCCESS",
                body: """<!DOCTYPE html>
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517
                <html>
                <head>
                <meta charset="UTF-8">
                </head>
                <body leftmargin="8" marginwidth="0" topmargin="8" marginheight="4" offset="0">
                    <table width="95%" cellpadding="0" cellspacing="0" style="font-size: 16pt; font-family: Tahoma, Arial, Helvetica, sans-serif">
                        <tr>
                            <td><br />
                                <b><font color="#0B610B"><font size="6">构建信息</font></font></b>
                                <hr size="2" width="100%" align="center" /></td>
                        </tr>
                        <tr>
                            <td>
                                <ul>
                                <div style="font-size:18px">
518
                                    <li>构建名称>>分支:${env.BRANCH_NAME}</li>
519 520
                                    <li>构建结果:<span style="color:green"> Successful </span></li>
                                    <li>构建编号:${BUILD_NUMBER}</li>
521
                                    <li>触发用户:${env.CHANGE_AUTHOR}</li>
L
fix  
liuyq-617 已提交
522
                                    <li>提交信息:${env.CHANGE_TITLE}</li>
523 524 525 526 527 528 529 530
                                    <li>构建地址:<a href=${BUILD_URL}>${BUILD_URL}</a></li>
                                    <li>构建日志:<a href=${BUILD_URL}console>${BUILD_URL}console</a></li>
                                </div>
                                </ul>
                            </td>
                        </tr>
                    </table></font>
                </body>
531
                </html>""",
L
liuyq-617 已提交
532
                to: "${env.CHANGE_AUTHOR_EMAIL}",
533 534 535 536 537
                from: "support@taosdata.com"
            )
        }
        failure {
            emailext (
538 539
                subject: "PR-result: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' FAIL",
                body: """<!DOCTYPE html>
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554
                <html>
                <head>
                <meta charset="UTF-8">
                </head>
                <body leftmargin="8" marginwidth="0" topmargin="8" marginheight="4" offset="0">
                    <table width="95%" cellpadding="0" cellspacing="0" style="font-size: 16pt; font-family: Tahoma, Arial, Helvetica, sans-serif">
                        <tr>
                            <td><br />
                                <b><font color="#0B610B"><font size="6">构建信息</font></font></b>
                                <hr size="2" width="100%" align="center" /></td>
                        </tr>
                        <tr>
                            <td>
                                <ul>
                                <div style="font-size:18px">
555
                                    <li>构建名称>>分支:${env.BRANCH_NAME}</li>
L
liuyq-617 已提交
556
                                    <li>构建结果:<span style="color:red"> Failure </span></li>
557
                                    <li>构建编号:${BUILD_NUMBER}</li>
558
                                    <li>触发用户:${env.CHANGE_AUTHOR}</li>
L
fix  
liuyq-617 已提交
559
                                    <li>提交信息:${env.CHANGE_TITLE}</li>
560 561 562 563 564 565 566 567
                                    <li>构建地址:<a href=${BUILD_URL}>${BUILD_URL}</a></li>
                                    <li>构建日志:<a href=${BUILD_URL}console>${BUILD_URL}console</a></li>
                                </div>
                                </ul>
                            </td>
                        </tr>
                    </table></font>
                </body>
568
                </html>""",
L
liuyq-617 已提交
569
                to: "${env.CHANGE_AUTHOR_EMAIL}",
570 571 572
                from: "support@taosdata.com"
            )
        }
573
    }
X
xiaolei li 已提交
574
}
L
liuyq-617 已提交
575