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

T
tangfangzhi 已提交
7 8
win_test_stage = 0
linux_ready = 0
9 10
linux_node_ip = ""
linux_node_pass = ""
L
liuyq-617 已提交
11 12

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

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

T
tangfangzhi 已提交
23 24 25
        if (currentBuildNumber == build.getNumber().toInteger()) {
            continue;
        }
L
liuyq-617 已提交
26

T
tangfangzhi 已提交
27 28
        build.doKill()    //doTerm(),doKill(),doTerm()
    }
L
liuyq-617 已提交
29 30 31 32
}
//  abort previous build
abortPreviousBuilds()
def abort_previous(){
T
tangfangzhi 已提交
33 34 35
    def buildNumber = env.BUILD_NUMBER as int
    if (buildNumber > 1) milestone(buildNumber - 1)
    milestone(buildNumber)
L
liuyq-617 已提交
36 37
}
def pre_test(){
38 39 40 41 42 43 44 45 46 47 48 49
    sh '''
        hostname
        date
    '''
    sh '''
        cd ${WK}
        git reset --hard
        git fetch || git fetch
        cd ${WKC}
        git reset --hard
        git fetch || git fetch
    '''
L
liuyq-617 已提交
50
    script {
T
tangfangzhi 已提交
51 52
        if (env.CHANGE_TARGET == 'master') {
            sh '''
T
tangfangzhi 已提交
53 54
                cd ${WK}
                git checkout master
T
tangfangzhi 已提交
55 56 57 58 59
                cd ${WKC}
                git checkout master
            '''
        } else if(env.CHANGE_TARGET == '2.0') {
            sh '''
T
tangfangzhi 已提交
60 61
                cd ${WK}
                git checkout 2.0
T
tangfangzhi 已提交
62 63 64 65 66
                cd ${WKC}
                git checkout 2.0
            '''
        } else if(env.CHANGE_TARGET == '3.0') {
            sh '''
T
tangfangzhi 已提交
67 68
                cd ${WK}
                git checkout 3.0
T
tangfangzhi 已提交
69 70 71 72 73
                cd ${WKC}
                git checkout 3.0
            '''
        } else {
            sh '''
T
tangfangzhi 已提交
74 75
                cd ${WK}
                git checkout develop
T
tangfangzhi 已提交
76 77 78
                cd ${WKC}
                git checkout develop
            '''
L
liuyq-617 已提交
79
        }
T
tangfangzhi 已提交
80
    }
T
tangfangzhi 已提交
81 82 83 84 85 86
    if (env.CHANGE_URL =~ /\/TDengine\//) {
        sh '''
            cd ${WKC}
            git pull >/dev/null
            git fetch origin +refs/pull/${CHANGE_ID}/merge
            git checkout -qf FETCH_HEAD
87
            git log -5
T
tangfangzhi 已提交
88 89
            cd ${WK}
            git pull >/dev/null
90
            git log -5
T
tangfangzhi 已提交
91 92 93 94 95 96 97
        '''
    } else if (env.CHANGE_URL =~ /\/TDinternal\//) {
        sh '''
            cd ${WK}
            git pull >/dev/null
            git fetch origin +refs/pull/${CHANGE_ID}/merge
            git checkout -qf FETCH_HEAD
98
            git log -5
T
tangfangzhi 已提交
99 100
            cd ${WKC}
            git pull >/dev/null
101
            git log -5
T
tangfangzhi 已提交
102 103 104 105 106 107
        '''
    } else {
        sh '''
            echo "unmatched reposiotry ${CHANGE_URL}"
        '''
    }
T
tangfangzhi 已提交
108
    sh '''
L
liuyq-617 已提交
109
        cd ${WKC}
T
tangfangzhi 已提交
110 111 112 113 114 115
        git submodule update --init --recursive
    '''
    sh '''
        cd ${WKPY}
        git reset --hard
        git pull
L
liuyq-617 已提交
116
    '''
T
tangfangzhi 已提交
117 118 119 120 121
    return 1
}
def pre_test_win(){
    bat '''
        hostname
T
tangfangzhi 已提交
122 123
        ipconfig
        set
T
tangfangzhi 已提交
124 125
        date /t
        time /t
126
        rd /s /Q C:\\workspace\\%EXECUTOR_NUMBER%\\TDinternal\\debug || exit 0
T
tangfangzhi 已提交
127 128
    '''
    bat '''
129 130 131
        cd C:\\workspace\\%EXECUTOR_NUMBER%\\TDinternal
        git reset --hard
        git fetch || git fetch
T
tangfangzhi 已提交
132 133
    '''
    bat '''
134
        cd C:\\workspace\\%EXECUTOR_NUMBER%\\TDinternal\\community
T
tangfangzhi 已提交
135 136 137 138 139 140
        git reset --hard
        git fetch || git fetch
    '''
    script {
        if (env.CHANGE_TARGET == 'master') {
            bat '''
141 142
                cd C:\\workspace\\%EXECUTOR_NUMBER%\\TDinternal
                git checkout master
T
tangfangzhi 已提交
143 144
            '''
            bat '''
145
                cd C:\\workspace\\%EXECUTOR_NUMBER%\\TDinternal\\community
T
tangfangzhi 已提交
146 147 148 149
                git checkout master
            '''
        } else if(env.CHANGE_TARGET == '2.0') {
            bat '''
150 151
                cd C:\\workspace\\%EXECUTOR_NUMBER%\\TDinternal
                git checkout 2.0
T
tangfangzhi 已提交
152 153
            '''
            bat '''
154
                cd C:\\workspace\\%EXECUTOR_NUMBER%\\TDinternal\\community
T
tangfangzhi 已提交
155 156 157 158
                git checkout 2.0
            '''
        } else if(env.CHANGE_TARGET == '3.0') {
            bat '''
159 160
                cd C:\\workspace\\%EXECUTOR_NUMBER%\\TDinternal
                git checkout 3.0
T
tangfangzhi 已提交
161 162
            '''
            bat '''
163
                cd C:\\workspace\\%EXECUTOR_NUMBER%\\TDinternal\\community
T
tangfangzhi 已提交
164 165 166 167
                git checkout 3.0
            '''
        } else {
            bat '''
168 169
                cd C:\\workspace\\%EXECUTOR_NUMBER%\\TDinternal
                git checkout develop
T
tangfangzhi 已提交
170 171
            '''
            bat '''
172
                cd C:\\workspace\\%EXECUTOR_NUMBER%\\TDinternal\\community
T
tangfangzhi 已提交
173 174 175 176
                git checkout develop
            '''
        }
    }
177 178 179 180 181
    script {
        if (env.CHANGE_URL =~ /\/TDengine\//) {
            bat '''
                cd C:\\workspace\\%EXECUTOR_NUMBER%\\TDinternal
                git pull
T
tangfangzhi 已提交
182 183
            '''
            bat '''
184 185
                cd C:\\workspace\\%EXECUTOR_NUMBER%\\TDinternal\\community
                git pull
T
tangfangzhi 已提交
186 187 188 189 190 191 192
            '''
            bat '''
                cd C:\\workspace\\%EXECUTOR_NUMBER%\\TDinternal\\community
                git fetch origin +refs/pull/%CHANGE_ID%/merge
            '''
            bat '''
                cd C:\\workspace\\%EXECUTOR_NUMBER%\\TDinternal\\community
193 194 195 196 197 198
                git checkout -qf FETCH_HEAD
            '''
        } else if (env.CHANGE_URL =~ /\/TDinternal\//) {
            bat '''
                cd C:\\workspace\\%EXECUTOR_NUMBER%\\TDinternal
                git pull
T
tangfangzhi 已提交
199 200 201 202 203 204 205
            '''
            bat '''
                cd C:\\workspace\\%EXECUTOR_NUMBER%\\TDinternal
                git fetch origin +refs/pull/%CHANGE_ID%/merge
            '''
            bat '''
                cd C:\\workspace\\%EXECUTOR_NUMBER%\\TDinternal
206
                git checkout -qf FETCH_HEAD
T
tangfangzhi 已提交
207 208
            '''
            bat '''
209 210 211 212
                cd C:\\workspace\\%EXECUTOR_NUMBER%\\TDinternal\\community
                git pull
            '''
        } else {
T
tangfangzhi 已提交
213 214
            bat '''
                echo "unmatched reposiotry %CHANGE_URL%"
215 216 217
            '''
        }
    }
T
tangfangzhi 已提交
218 219
    bat '''
        cd C:\\workspace\\%EXECUTOR_NUMBER%\\TDinternal
T
tangfangzhi 已提交
220
        git branch
T
tangfangzhi 已提交
221 222 223 224
        git log -5
    '''
    bat '''
        cd C:\\workspace\\%EXECUTOR_NUMBER%\\TDinternal\\community
T
tangfangzhi 已提交
225
        git branch
T
tangfangzhi 已提交
226 227
        git log -5
    '''
T
tangfangzhi 已提交
228
    bat '''
229 230
        cd C:\\workspace\\%EXECUTOR_NUMBER%\\TDinternal\\community
        git submodule update --init --recursive
T
tangfangzhi 已提交
231
    '''
232 233 234 235 236 237 238 239 240 241
    bat '''
        cd C:\\workspace\\%EXECUTOR_NUMBER%\\taos-connector-python
        git branch
        git reset --hard
        git pull
    '''
    bat '''
        cd C:\\workspace\\%EXECUTOR_NUMBER%\\taos-connector-python
        git log -5
    '''
T
tangfangzhi 已提交
242 243 244 245 246
}
def pre_test_build_win() {
    bat '''
        echo "building ..."
        time /t
247
        cd C:\\workspace\\%EXECUTOR_NUMBER%\\TDinternal
T
tangfangzhi 已提交
248 249
        mkdir debug
        cd debug
T
tangfangzhi 已提交
250
        time /t
T
tangfangzhi 已提交
251 252
        call "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Auxiliary\\Build\\vcvarsall.bat" x64
        set CL=/MP8
T
tangfangzhi 已提交
253 254
        echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> cmake"
        time /t
T
tangfangzhi 已提交
255
        cmake .. -G "NMake Makefiles JOM" || exit 7
T
tangfangzhi 已提交
256
        echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> jom -j 6"
257
        time /t
T
tangfangzhi 已提交
258
        jom -j 6 || exit 8
T
tangfangzhi 已提交
259
        time /t
T
tangfangzhi 已提交
260
    '''
261 262 263
    bat '''
        cd C:\\workspace\\%EXECUTOR_NUMBER%\\taos-connector-python
        python -m pip install .
T
tangfangzhi 已提交
264
        xcopy /e/y/i/f C:\\workspace\\%EXECUTOR_NUMBER%\\TDinternal\\debug\\build\\lib\\taos.dll C:\\Windows\\System32
265
    '''
L
liuyq-617 已提交
266 267
    return 1
}
T
tangfangzhi 已提交
268
def run_win_ctest() {
T
tangfangzhi 已提交
269 270 271 272 273 274 275 276
    bat '''
        echo "windows ctest ..."
        time /t
        cd C:\\workspace\\%EXECUTOR_NUMBER%\\TDinternal\\debug
        ctest -j 6 || exit 7
        time /t
    '''
}
T
tangfangzhi 已提交
277
def run_win_test() {
278
    echo "LINUX NODE: ${linux_node_ip} - ${linux_node_pass}"
T
tangfangzhi 已提交
279 280
    bat '''
        echo "windows test ..."
T
tangfangzhi 已提交
281 282
        cd C:\\workspace\\%EXECUTOR_NUMBER%\\taos-connector-python
        python -m pip install .
T
tangfangzhi 已提交
283 284 285
        time /t
        cd C:\\workspace\\%EXECUTOR_NUMBER%\\TDinternal\\community\\tests\\system-test
        echo "testing ..."
286
        test-all.bat  "{\\\"host\\\":\\\"''' + linux_node_ip + '''\\\",\\\"port\\\":22,\\\"user\\\":\\\"root\\\",\\\"password\\\":\\\"''' + linux_node_pass + '''\\\",\\\"path\\\":\\\"/var/lib/jenkins/workspace/TDinternal\\\"}"
T
tangfangzhi 已提交
287 288 289
        time /t
    '''
}
L
liuyq-617 已提交
290 291

pipeline {
T
tangfangzhi 已提交
292 293 294
    agent none
    options { skipDefaultCheckout() } 
    environment{
T
tangfangzhi 已提交
295
        WKDIR = '/var/lib/jenkins/workspace'
T
tangfangzhi 已提交
296
        WK = '/var/lib/jenkins/workspace/TDinternal'
T
tangfangzhi 已提交
297 298
        WKC = '/var/lib/jenkins/workspace/TDinternal/community'
        WKPY = '/var/lib/jenkins/workspace/taos-connector-python'
T
tangfangzhi 已提交
299 300 301 302
    }
    stages {
        stage('run test') {
            parallel {
T
tangfangzhi 已提交
303 304 305
                stage('windows test') {
                    agent{label " windows10_01 || windows10_02 || windows10_03 || windows10_04 "}
                    steps {
T
tangfangzhi 已提交
306
                        catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
T
tangfangzhi 已提交
307
                            timeout(time: 55, unit: 'MINUTES'){
T
tangfangzhi 已提交
308 309 310
                                pre_test_win()
                                pre_test_build_win()
                                run_win_ctest()
T
tangfangzhi 已提交
311 312 313 314
                                script {
                                    while(linux_ready == 0) {
                                        sleep(8)
                                    }
T
tangfangzhi 已提交
315 316 317 318 319 320 321
                                }
                                run_win_test()
                            }
                        }
                        script {
                            win_test_stage = 1
                        }
T
tangfangzhi 已提交
322 323
                    }
                }
T
tangfangzhi 已提交
324
                stage('linux test') {
T
tangfangzhi 已提交
325
                    agent{label " worker03 || slave215 || slave217 || slave219 "}
T
tangfangzhi 已提交
326 327 328 329 330
                    options { skipDefaultCheckout() } 
                    when {
                        changeRequest()
                    }
                    steps {
331 332
                        script {
                            linux_node_ip = sh (
333
                                script: 'jq .ip /home/node_info.json | sed "s/\\\"//g"',
334 335 336
                                returnStdout: true
                            ).trim()
                            linux_node_pass = sh (
337
                                script: 'jq .password /home/node_info.json | sed "s/\\\"//g"',
338 339
                                returnStdout: true
                            ).trim()
340
                            echo "${linux_node_ip}:${linux_node_pass}"
341
                        }
T
tangfangzhi 已提交
342 343
                        catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
                            timeout(time: 40, unit: 'MINUTES'){
344
                                pre_test()
T
tangfangzhi 已提交
345 346 347 348
                                script {
                                    sh '''
                                        date
                                        rm -rf ${WKC}/debug
349
                                        cd ${WKC}/tests/parallel_test
T
tangfangzhi 已提交
350 351 352 353 354 355 356 357 358 359 360 361 362
                                        time ./container_build.sh -w ${WKDIR} -t 8 -e
                                        rm -f /tmp/cases.task
                                        ./collect_cases.sh -e
                                    '''
                                    sh '''
                                        cd ${WKC}/tests/parallel_test
                                        export DEFAULT_RETRY_TIME=2
                                        date
                                        timeout 2100 time ./run.sh -e -m /home/m.json -t /tmp/cases.task -b ${BRANCH_NAME}_${BUILD_ID} -l ${WKDIR}/log -o 480
                                    '''
                                }
                            }
                        }
T
tangfangzhi 已提交
363
                        catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
T
tangfangzhi 已提交
364
                            timeout(time: 15, unit: 'MINUTES'){
T
tangfangzhi 已提交
365 366 367 368
                                script {
                                    sh '''
                                        echo "packaging ..."
                                        date
369
                                        rm -rf ${WKC}/release/*
T
tangfangzhi 已提交
370 371 372 373
                                        cd ${WKC}/packaging
                                        ./release.sh -v cluster -n 3.0.0.100 -s static
                                        cd ${WKC}/release
                                        tar xzf TDengine-enterprise-server-3.0.0.100-Linux-x64.tar.gz
T
tangfangzhi 已提交
374
                                        cd TDengine-enterprise-server-3.0.0.100
T
tangfangzhi 已提交
375 376 377 378 379 380
                                        service taosd stop || :
                                        rm -rf /var/lib/taos
                                        ./install.sh -e no
                                        service taosd start
                                        sleep 20
                                        service taosd status
T
tangfangzhi 已提交
381 382
                                        rm -rf ${WK}/debug
                                        mv ${WKC}/debug ${WK}/
T
tangfangzhi 已提交
383
                                    '''
T
tangfangzhi 已提交
384
                                    sh '''
T
tangfangzhi 已提交
385 386
                                        cd ${WKPY}
                                        pip3 install .
T
tangfangzhi 已提交
387
                                    '''
388 389 390 391 392 393 394 395 396 397
                                }
                            }
                        }
                        script {
                            linux_ready = 1
                        }
                        script {
                            while(win_test_stage == 0){
                                sleep(12)
                            }
T
tangfangzhi 已提交
398 399 400
                        }
                    }
                }
L
liuyq-617 已提交
401
            }
T
tangfangzhi 已提交
402 403 404
        }
    }
    post {  
L
liuyq-617 已提交
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482
        success {
            emailext (
                subject: "PR-result: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' SUCCESS",
                body: """<!DOCTYPE html>
                <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">
                                    <li>构建名称>>分支:${env.BRANCH_NAME}</li>
                                    <li>构建结果:<span style="color:green"> Successful </span></li>
                                    <li>构建编号:${BUILD_NUMBER}</li>
                                    <li>触发用户:${env.CHANGE_AUTHOR}</li>
                                    <li>提交信息:${env.CHANGE_TITLE}</li>
                                    <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>
                </html>""",
                to: "${env.CHANGE_AUTHOR_EMAIL}",
                from: "support@taosdata.com"
            )
        }
        failure {
            emailext (
                subject: "PR-result: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' FAIL",
                body: """<!DOCTYPE html>
                <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">
                                    <li>构建名称>>分支:${env.BRANCH_NAME}</li>
                                    <li>构建结果:<span style="color:red"> Failure </span></li>
                                    <li>构建编号:${BUILD_NUMBER}</li>
                                    <li>触发用户:${env.CHANGE_AUTHOR}</li>
                                    <li>提交信息:${env.CHANGE_TITLE}</li>
                                    <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>
                </html>""",
                to: "${env.CHANGE_AUTHOR_EMAIL}",
                from: "support@taosdata.com"
            )
        }
    } 
}