Jenkinsfile 15.8 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
properties([pipelineTriggers([githubPush()])])
node {
L
liuyq-617 已提交
6
    git url: 'https://github.com/taosdata/TDengine.git'
7 8
}

L
liuyq-617 已提交
9
def skipbuild=0
L
liuyq-617 已提交
10
def win_stop=0
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 '''
L
fix  
liuyq-617 已提交
43 44
    killall -9 taosd ||echo "no taosd running"
    killall -9 gdb || echo "no gdb running"
L
liuyq-617 已提交
45
    killall -9 python3.8 || echo "no python program running"
46
    cd ${WKC}
L
fix  
liuyq-617 已提交
47 48 49 50
    git reset --hard HEAD~10 >/dev/null
    '''
    script {
      if (env.CHANGE_TARGET == 'master') {
L
fix  
liuyq-617 已提交
51 52 53 54
        sh '''
        cd ${WKC}
        git checkout master
        '''
L
fix  
liuyq-617 已提交
55
        }
56
      else if(env.CHANGE_TARGET == '2.0'){
L
fix  
liuyq-617 已提交
57 58
        sh '''
        cd ${WKC}
59
        git checkout 2.0
L
fix  
liuyq-617 已提交
60
        '''
L
fix  
liuyq-617 已提交
61
      } 
62 63 64 65 66 67
      else{
        sh '''
        cd ${WKC}
        git checkout develop
        '''
      }
L
fix  
liuyq-617 已提交
68 69
    }
    sh'''
L
fix  
liuyq-617 已提交
70
    cd ${WKC}
L
liuyq-617 已提交
71
    git pull >/dev/null
L
liuyq-617 已提交
72
    git fetch origin +refs/pull/${CHANGE_ID}/merge
73
    git checkout -qf FETCH_HEAD
L
liuyq-617 已提交
74
    git clean -dfx
75
    cd ${WK}
L
enhance  
liuyq-617 已提交
76
    git reset --hard HEAD~10
L
fix  
liuyq-617 已提交
77 78 79
    '''
    script {
      if (env.CHANGE_TARGET == 'master') {
L
fix  
liuyq-617 已提交
80
        sh '''
L
fix  
liuyq-617 已提交
81
        cd ${WK}
L
fix  
liuyq-617 已提交
82 83
        git checkout master
        '''
L
fix  
liuyq-617 已提交
84
        }
85 86 87 88 89 90 91
      else if(env.CHANGE_TARGET == '2.0'){
        sh '''
        cd ${WK}
        git checkout 2.0
        '''
      } 
      else{
L
fix  
liuyq-617 已提交
92
        sh '''
L
fix  
liuyq-617 已提交
93
        cd ${WK}
L
fix  
liuyq-617 已提交
94 95
        git checkout develop
        '''
L
fix  
liuyq-617 已提交
96 97 98
      } 
    }
    sh '''
99
    cd ${WK}
L
fix  
liuyq-617 已提交
100
    git pull >/dev/null 
L
fix  
liuyq-617 已提交
101

102 103
    export TZ=Asia/Harbin
    date
L
liuyq-617 已提交
104
    git clean -dfx
105 106 107 108 109 110
    mkdir debug
    cd debug
    cmake .. > /dev/null
    make > /dev/null
    make install > /dev/null
    cd ${WKC}/tests
L
liuyq-617 已提交
111
    pip3 install ${WKC}/src/connector/python/
L
liuyq-617 已提交
112
    '''
113 114
    return 1
}
L
liuyq-617 已提交
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 169 170 171 172 173
def pre_test_win(){
    bat '''
    cd C:\\
    rd /s /Q C:\\TDengine
    cd C:\\workspace\\TDinternal
    rd /s /Q C:\\workspace\\TDinternal\\debug
    cd C:\\workspace\\TDinternal\\community
    git reset --hard HEAD~10 
    '''
    script {
      if (env.CHANGE_TARGET == 'master') {
        bat '''
        cd C:\\workspace\\TDinternal\\community
        git checkout master
        '''
        }
      else if(env.CHANGE_TARGET == '2.0'){
        bat '''
        cd C:\\workspace\\TDinternal\\community
        git checkout 2.0
        '''
      } 
      else{
        bat '''
        cd C:\\workspace\\TDinternal\\community
        git checkout develop
        '''
      }
    }
    bat'''
    cd C:\\workspace\\TDinternal\\community
    git pull 
    git fetch origin +refs/pull/%CHANGE_ID%/merge
    git checkout -qf FETCH_HEAD
    git clean -dfx
    cd C:\\workspace\\TDinternal
    git reset --hard HEAD~10
    '''
    script {
      if (env.CHANGE_TARGET == 'master') {
        bat '''
        cd C:\\workspace\\TDinternal
        git checkout master
        '''
        }
      else if(env.CHANGE_TARGET == '2.0'){
        bat '''
        cd C:\\workspace\\TDinternal
        git checkout 2.0
        '''
      } 
      else{
        bat '''
        cd C:\\workspace\\TDinternal
        git checkout develop
        '''
      } 
    }
    bat '''
L
liuyq-617 已提交
174
    taskkill /f /t /im python.exe
L
liuyq-617 已提交
175 176
    cd C:\\workspace\\TDinternal
    git pull 
L
liuyq-617 已提交
177

L
liuyq-617 已提交
178 179 180 181 182 183
    date
    git clean -dfx
    mkdir debug
    cd debug
    call "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\vcvarsall.bat" amd64
    cmake ../ -G "NMake Makefiles" 
L
liuyq-617 已提交
184 185
    nmake || exit 8
    nmake install || exit 8
L
liuyq-617 已提交
186
    xcopy /e/y/i/f C:\\workspace\\TDinternal\\debug\\build\\lib\\taos.dll C:\\Windows\\System32 || exit 8
L
liuyq-617 已提交
187 188 189 190 191 192
    cd C:\\workspace\\TDinternal\\community\\src\\connector\\python
    python -m pip install .
    
    '''
    return 1
}
Y
Yiqing Liu 已提交
193
pipeline {
L
liuyq-617 已提交
194 195 196 197 198
  agent none
  environment{
      WK = '/var/lib/jenkins/workspace/TDinternal'
      WKC= '/var/lib/jenkins/workspace/TDinternal/community'
  }
Y
Yiqing Liu 已提交
199
  stages {
L
change  
liuyq-617 已提交
200
      stage('pre_build'){
201
          agent{label 'master'}
L
liuyq-617 已提交
202 203 204
          when {
              changeRequest()
          }
205
          steps {
L
change  
liuyq-617 已提交
206 207 208 209
            script{
              abort_previous()
              abortPreviousBuilds()
            }
L
liuyq-617 已提交
210
          sh'''
211
          rm -rf ${WORKSPACE}.tes
L
fix  
liuyq-617 已提交
212 213
          cp -r ${WORKSPACE} ${WORKSPACE}.tes
          cd ${WORKSPACE}.tes
L
test  
liuyq-617 已提交
214
          git fetch
215 216 217 218 219 220 221
          '''
          script {
            if (env.CHANGE_TARGET == 'master') {
              sh '''
              git checkout master
              '''
              }
L
test  
liuyq-617 已提交
222 223 224 225 226 227
            else if(env.CHANGE_TARGET == '2.0'){
              sh '''
              git checkout 2.0
              '''
            } 
            else{
228 229 230 231 232 233
              sh '''
              git checkout develop
              '''
            } 
          }
          sh'''
L
liuyq-617 已提交
234
          git fetch origin +refs/pull/${CHANGE_ID}/merge
235
          git checkout -qf FETCH_HEAD
L
fix  
liuyq-617 已提交
236
          '''     
237

L
liuyq-617 已提交
238 239 240 241
          script{  
            skipbuild='2'     
            skipbuild=sh(script: "git log -2 --pretty=%B | fgrep -ie '[skip ci]' -e '[ci skip]' && echo 1 || echo 2", returnStdout:true)
            println skipbuild
242
          }
L
fix  
liuyq-617 已提交
243
          sh'''
L
liuyq-617 已提交
244
          rm -rf ${WORKSPACE}.tes
L
fix  
liuyq-617 已提交
245
          '''
246 247
          }
      }
L
change  
liuyq-617 已提交
248
      stage('Parallel test stage') {
L
liuyq-617 已提交
249 250
        //only build pr
        when {
L
liuyq-617 已提交
251
          allOf{
L
liuyq-617 已提交
252
              changeRequest()
L
liuyq-617 已提交
253 254
               expression{
                return skipbuild.trim() == '2'
255
              }
L
liuyq-617 已提交
256
            }
L
liuyq-617 已提交
257
          }
Y
Yiqing Liu 已提交
258
      parallel {
L
liuyq-617 已提交
259
        stage('python_1_s1') {
L
liuyq-617 已提交
260
          agent{label " slave1 || slave11 "}
L
liuyq-617 已提交
261
          steps {
L
liuyq-617 已提交
262
            
263
            pre_test()
L
liuyq-617 已提交
264
            timeout(time: 55, unit: 'MINUTES'){
L
liuyq-617 已提交
265
              sh '''
L
liuyq-617 已提交
266
              date
L
liuyq-617 已提交
267 268 269 270 271
              cd ${WKC}/tests
              ./test-all.sh p1
              date'''
            }
            
L
liuyq-617 已提交
272 273
          }
        }
L
liuyq-617 已提交
274
        stage('python_2_s5') {
L
liuyq-617 已提交
275
          agent{label " slave5 || slave15 "}
L
liuyq-617 已提交
276 277 278
          steps {
            
            pre_test()
L
liuyq-617 已提交
279
            timeout(time: 55, unit: 'MINUTES'){
280 281 282 283 284
                sh '''
                date
                cd ${WKC}/tests
                ./test-all.sh p2
                date'''
L
liuyq-617 已提交
285 286 287 288
            }
          }
        }
        stage('python_3_s6') {
L
liuyq-617 已提交
289
          agent{label " slave6 || slave16 "}
L
liuyq-617 已提交
290
          steps {     
L
liuyq-617 已提交
291
            timeout(time: 55, unit: 'MINUTES'){       
L
liuyq-617 已提交
292 293 294 295 296 297 298
              pre_test()
              sh '''
              date
              cd ${WKC}/tests
              ./test-all.sh p3
              date'''
            }
L
liuyq-617 已提交
299 300
          }
        }
L
liuyq-617 已提交
301
        stage('test_b1_s2') {
L
liuyq-617 已提交
302
          agent{label " slave2 || slave12 "}
L
liuyq-617 已提交
303
          steps {     
L
liuyq-617 已提交
304
            timeout(time: 55, unit: 'MINUTES'){       
L
liuyq-617 已提交
305
              pre_test()
L
liuyq-617 已提交
306 307 308 309 310 311 312 313 314 315 316 317
              sh '''
                rm -rf /var/lib/taos/*
                rm -rf /var/log/taos/*
                nohup taosd >/dev/null &
                sleep 10
              '''
              sh '''
              cd ${WKC}/tests/examples/nodejs
              npm install td2.0-connector > /dev/null 2>&1
              node nodejsChecker.js host=localhost
              '''
              sh '''
L
liuyq-617 已提交
318 319 320
              cd ${WKC}/tests/examples/C#/taosdemo
              mcs -out:taosdemo *.cs > /dev/null 2>&1
              ./taosdemo -c /etc/taos -y
L
liuyq-617 已提交
321 322 323 324 325
              '''
              sh '''
                cd ${WKC}/tests/gotest
                bash batchtest.sh
              '''
L
liuyq-617 已提交
326 327 328 329 330
              sh '''
              cd ${WKC}/tests
              ./test-all.sh b1fq
              date'''
            }
Y
Yiqing Liu 已提交
331 332
          }
        }
L
liuyq-617 已提交
333
        stage('test_crash_gen_s3') {
L
liuyq-617 已提交
334
          agent{label " slave3 || slave13 "}
335
          
Y
Yiqing Liu 已提交
336
          steps {
337
            pre_test()
L
liuyq-617 已提交
338 339 340 341 342
            timeout(time: 60, unit: 'MINUTES'){
              sh '''
              cd ${WKC}/tests/pytest
              ./crash_gen.sh -a -p -t 4 -s 2000
              '''
343 344
            }
            timeout(time: 60, unit: 'MINUTES'){
P
Ping Xiao 已提交
345 346 347 348 349 350
              sh '''
              cd ${WKC}/tests/pytest
              rm -rf /var/lib/taos/*
              rm -rf /var/log/taos/*
              ./handle_crash_gen_val_log.sh
              '''
351 352 353 354 355 356
              sh '''
              cd ${WKC}/tests/pytest
              rm -rf /var/lib/taos/*
              rm -rf /var/log/taos/*
              ./handle_taosd_val_log.sh
              '''
L
liuyq-617 已提交
357
            }
L
liuyq-617 已提交
358
            timeout(time: 55, unit: 'MINUTES'){
359 360 361 362 363 364
                sh '''
                date
                cd ${WKC}/tests
                ./test-all.sh b2fq
                date
                '''
L
test  
liuyq-617 已提交
365
            }                     
Y
Yiqing Liu 已提交
366 367
          }
        }
L
liuyq-617 已提交
368
        stage('test_valgrind_s4') {
L
liuyq-617 已提交
369
          agent{label " slave4 || slave14 "}
L
liuyq-617 已提交
370

Y
Yiqing Liu 已提交
371
          steps {
372 373 374 375 376 377 378
            pre_test()
            catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
                sh '''
                cd ${WKC}/tests/pytest
                ./valgrind-test.sh 2>&1 > mem-error-out.log
                ./handle_val_log.sh
                '''
L
liuyq-617 已提交
379
            }     
L
liuyq-617 已提交
380
            timeout(time: 55, unit: 'MINUTES'){      
L
liuyq-617 已提交
381 382 383 384 385
              sh '''
              date
              cd ${WKC}/tests
              ./test-all.sh b3fq
              date'''
P
change  
Ping Xiao 已提交
386 387 388 389 390
              sh '''
              date
              cd ${WKC}/tests
              ./test-all.sh full example
              date'''
L
liuyq-617 已提交
391
            }
Y
Yiqing Liu 已提交
392 393
          }
        }
L
liuyq-617 已提交
394
        stage('test_b4_s7') {
L
liuyq-617 已提交
395
          agent{label " slave7 || slave17 "}
L
liuyq-617 已提交
396
          steps {     
L
liuyq-617 已提交
397
            timeout(time: 55, unit: 'MINUTES'){       
L
liuyq-617 已提交
398 399 400 401 402
              pre_test()
              sh '''
              date
              cd ${WKC}/tests
              ./test-all.sh b4fq
L
fix  
liuyq-617 已提交
403
              cd ${WKC}/tests
L
liuyq-617 已提交
404
              ./test-all.sh p4
405 406
              cd ${WKC}/tests
              ./test-all.sh full jdbc
P
Ping Xiao 已提交
407 408
              cd ${WKC}/tests
              ./test-all.sh full unit
L
liuyq-617 已提交
409 410 411 412 413
              date'''
            }
          }
        }
        stage('test_b5_s8') {
L
liuyq-617 已提交
414
          agent{label " slave8 || slave18 "}
L
liuyq-617 已提交
415
          steps {     
L
liuyq-617 已提交
416
            timeout(time: 55, unit: 'MINUTES'){       
L
liuyq-617 已提交
417 418 419 420 421 422 423 424 425 426
              pre_test()
              sh '''
              date
              cd ${WKC}/tests
              ./test-all.sh b5fq
              date'''
            }
          }
        }
        stage('test_b6_s9') {
L
liuyq-617 已提交
427
          agent{label " slave9 || slave19 "}
L
liuyq-617 已提交
428
          steps {     
L
liuyq-617 已提交
429
            timeout(time: 55, unit: 'MINUTES'){       
L
liuyq-617 已提交
430 431 432 433 434 435 436 437 438 439
              pre_test()
              sh '''
              date
              cd ${WKC}/tests
              ./test-all.sh b6fq
              date'''
            }
          }
        }
        stage('test_b7_s10') {
L
liuyq-617 已提交
440
          agent{label " slave10 || slave20 "}
L
liuyq-617 已提交
441
          steps {     
L
liuyq-617 已提交
442
            timeout(time: 55, unit: 'MINUTES'){       
L
liuyq-617 已提交
443 444 445 446 447
              pre_test()
              sh '''
              date
              cd ${WKC}/tests
              ./test-all.sh b7fq
P
change  
Ping Xiao 已提交
448
              date'''              
L
liuyq-617 已提交
449 450
            }
          }
L
liuyq-617 已提交
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469
        } 
        
        stage('build'){
          agent{label " wintest "}
          steps {
            pre_test()
            script{             
                while(win_stop == 0){
                  sleep(1)
                  }
              }
            }
        }
        stage('test'){
          agent{label "win"}
          steps{
            
            catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
                pre_test_win()
L
liuyq-617 已提交
470
                timeout(time: 20, unit: 'MINUTES'){
L
liuyq-617 已提交
471 472 473 474
                bat'''
                cd C:\\workspace\\TDinternal\\community\\tests\\pytest
                .\\test-all.bat Wintest
                '''
L
liuyq-617 已提交
475
                }
L
liuyq-617 已提交
476 477 478 479 480 481 482 483
            }     
            script{
              win_stop=1
            }
          }
        }
          
               
Y
Yiqing Liu 已提交
484 485
    }
  }
L
liuyq-617 已提交
486
  }
L
liuyq-617 已提交
487
  post {  
488 489
        success {
            emailext (
490 491
                subject: "PR-result: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' SUCCESS",
                body: """<!DOCTYPE html>
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506
                <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">
507
                                    <li>构建名称>>分支:${env.BRANCH_NAME}</li>
508 509
                                    <li>构建结果:<span style="color:green"> Successful </span></li>
                                    <li>构建编号:${BUILD_NUMBER}</li>
510
                                    <li>触发用户:${env.CHANGE_AUTHOR}</li>
L
fix  
liuyq-617 已提交
511
                                    <li>提交信息:${env.CHANGE_TITLE}</li>
512 513
                                    <li>构建地址:<a href=${BUILD_URL}>${BUILD_URL}</a></li>
                                    <li>构建日志:<a href=${BUILD_URL}console>${BUILD_URL}console</a></li>
514
                                    
515 516 517 518 519 520
                                </div>
                                </ul>
                            </td>
                        </tr>
                    </table></font>
                </body>
521
                </html>""",
L
liuyq-617 已提交
522
                to: "${env.CHANGE_AUTHOR_EMAIL}",
523 524 525 526 527
                from: "support@taosdata.com"
            )
        }
        failure {
            emailext (
528 529
                subject: "PR-result: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' FAIL",
                body: """<!DOCTYPE html>
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544
                <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">
545
                                    <li>构建名称>>分支:${env.BRANCH_NAME}</li>
L
liuyq-617 已提交
546
                                    <li>构建结果:<span style="color:red"> Failure </span></li>
547
                                    <li>构建编号:${BUILD_NUMBER}</li>
548
                                    <li>触发用户:${env.CHANGE_AUTHOR}</li>
L
fix  
liuyq-617 已提交
549
                                    <li>提交信息:${env.CHANGE_TITLE}</li>
550 551
                                    <li>构建地址:<a href=${BUILD_URL}>${BUILD_URL}</a></li>
                                    <li>构建日志:<a href=${BUILD_URL}console>${BUILD_URL}console</a></li>
552
                                    
553 554 555 556 557 558
                                </div>
                                </ul>
                            </td>
                        </tr>
                    </table></font>
                </body>
559
                </html>""",
L
liuyq-617 已提交
560
                to: "${env.CHANGE_AUTHOR_EMAIL}",
561 562 563
                from: "support@taosdata.com"
            )
        }
L
liuyq-617 已提交
564
    } 
L
liuyq-617 已提交
565
}