Jenkinsfile2 18.4 KB
Newer Older
1 2 3 4 5 6
import hudson.model.Result
import hudson.model.*;
import jenkins.model.CauseOfInterruption
node {
}
def sync_source() {
T
tangfangzhi 已提交
7 8 9
    sh '''
        hostname
        date
T
tangfangzhi 已提交
10 11
        env
    '''
12 13 14
    sh '''
        cd ${WKC}
        [ -f src/connector/grafanaplugin/README.md ] && rm -f src/connector/grafanaplugin/README.md > /dev/null || echo "failed to remove grafanaplugin README.md"
15 16 17 18 19
        git reset --hard
        git fetch
        cd ${WK}
        git reset --hard
        git fetch
20 21 22 23 24
    '''
    script {
        if (env.CHANGE_TARGET == 'master') {
            sh '''
                cd ${WKC}
25
                git clean -fxd
26 27 28 29 30
                git checkout master
            '''
        } else if (env.CHANGE_TARGET == '2.0') {
            sh '''
                cd ${WKC}
31
                git clean -fxd
32 33 34 35 36
                git checkout 2.0
            '''
        } else if (env.CHANGE_TARGET == '2.4') {
            sh '''
                cd ${WKC}
37
                git clean -fxd
38 39
                git checkout 2.4
            '''
T
tangfangzhi 已提交
40 41 42 43 44 45
        } else if (env.CHANGE_TARGET == '2.6') {
            sh '''
                cd ${WKC}
                git clean -fxd
                git checkout 2.6
            '''
46 47 48
        } else {
            sh '''
                cd ${WKC}
49
                git clean -fxd
50 51 52 53
                git checkout develop
            '''
        }
    }
54
    sh '''
55
        export TZ=Asia/Harbin
56 57 58 59
        cd ${WKC}
        git remote prune origin
        [ -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
T
tangfangzhi 已提交
60
        git clean -dfx
T
tangfangzhi 已提交
61
        git log -5
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
    '''
    script {
        if (env.CHANGE_TARGET == 'master') {
            sh '''
                cd ${WK}
                git checkout master
            '''
        } else if (env.CHANGE_TARGET == '2.0') {
            sh '''
                cd ${WK}
                git checkout 2.0
            '''
        } else if (env.CHANGE_TARGET == '2.4') {
            sh '''
                cd ${WK}
                git checkout 2.4
            '''
T
tangfangzhi 已提交
79 80 81 82 83
        } else if (env.CHANGE_TARGET == '2.6') {
            sh '''
                cd ${WK}
                git checkout 2.6
            '''
84 85 86 87 88 89 90 91 92 93
        } else {
            sh '''
                cd ${WK}
                git checkout develop
            '''
        }
    }
    sh '''
        cd ${WK}
        git pull >/dev/null
T
tangfangzhi 已提交
94
        git clean -dfx
T
tangfangzhi 已提交
95
        git log -5
96 97 98 99 100 101 102 103
    '''
    script {
        if (env.CHANGE_URL =~ /\/TDengine\//) {
            sh '''
                echo "match /TDengine/ repository"
                cd ${WKC}
                git fetch origin +refs/pull/${CHANGE_ID}/merge
                git checkout -qf FETCH_HEAD
T
tangfangzhi 已提交
104 105 106 107
                git log -5
            '''
            sh '''
                cd ${WKC}
108 109 110
                rm -rf src/connector/python
                mkdir -p src/connector/python
                git clone --depth 1 https://github.com/taosdata/taos-connector-python src/connector/python || echo "failed to clone python connector"
111 112 113 114 115 116 117
            '''
        } else if (env.CHANGE_URL =~ /\/TDinternal\//) {
            sh '''
                echo "match /TDinternal/ repository"
                cd ${WK}
                git fetch origin +refs/pull/${CHANGE_ID}/merge
                git checkout -qf FETCH_HEAD
T
tangfangzhi 已提交
118 119 120 121
                git log -5
            '''
            sh '''
                cd ${WKC}
122 123 124
                rm -rf src/connector/python
                mkdir -p src/connector/python
                git clone --depth 1 https://github.com/taosdata/taos-connector-python src/connector/python || echo "failed to clone python connector"
125 126 127 128 129 130 131 132 133 134
            '''
        } else {
            sh '''
                echo "unmatched reposiotry ${CHANGE_URL}"
            '''
        }
    }
    sh '''
        cd ${WKC}
        git submodule update --init --recursive
135 136
    '''
}
137 138 139 140 141 142 143 144 145 146 147 148 149
def pre_test_arm64() {
    sync_source()
    sh '''
        cd ${WK}
        mkdir -p debug
        cd debug
        go env -w GOPROXY=https://goproxy.cn,direct
        go env -w GO111MODULE=on
        cmake .. -DBUILD_HTTP=false -DBUILD_TOOLS=true > /dev/null
        make -j8 >/dev/null
    '''
    return 1
}
150 151 152
def pre_test() {
    sync_source()
    sh '''
153 154
        cd ${WKC}/tests/parallel_test
        ./container_build.sh -w ${WKDIR} -t 8 >/dev/null
T
tangfangzhi 已提交
155 156 157 158 159 160 161 162 163 164 165 166 167
    '''
    return 1
}
def pre_test_mac() {
    sync_source()
    sh '''
        cd ${WK}
        mkdir -p debug
        cd debug
        go env -w GOPROXY=https://goproxy.cn,direct
        go env -w GO111MODULE=on
        cmake .. -DBUILD_TOOLS=false > /dev/null
        make -j8 >/dev/null
168 169 170
    '''
    return 1
}
T
tangfangzhi 已提交
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
def pre_test_win(){
    bat '''
        hostname
        ipconfig
        set
        date /t
        time /t
        taskkill /f /t /im python.exe
        taskkill /f /t /im bash.exe
        taskkill /f /t /im taosd.exe
        rd /s /Q %WIN_INTERNAL_ROOT%\\debug || echo "no debug folder"
        echo "clean environment done"
        exit 0
    '''
    bat '''
        cd %WIN_INTERNAL_ROOT%
        git reset --hard
    '''
    bat '''
        cd %WIN_COMMUNITY_ROOT%
        git reset --hard
    '''
    script {
        if (env.CHANGE_TARGET == 'master') {
            bat '''
                cd %WIN_INTERNAL_ROOT%
                git checkout master
            '''
            bat '''
                cd %WIN_COMMUNITY_ROOT%
                git checkout master
            '''
        } else if (env.CHANGE_TARGET == '2.0') {
            bat '''
                cd %WIN_INTERNAL_ROOT%
                git checkout 2.0
            '''
            bat '''
                cd %WIN_COMMUNITY_ROOT%
                git checkout 2.0
            '''
        } else if (env.CHANGE_TARGET == '2.4') {
            bat '''
                cd %WIN_INTERNAL_ROOT%
                git checkout 2.4
            '''
            bat '''
                cd %WIN_COMMUNITY_ROOT%
                git checkout 2.4
            '''
        } else if (env.CHANGE_TARGET == '2.6') {
            bat '''
                cd %WIN_INTERNAL_ROOT%
                git checkout 2.6
            '''
            bat '''
                cd %WIN_COMMUNITY_ROOT%
                git checkout 2.6
            '''
        } else {
            bat '''
                cd %WIN_INTERNAL_ROOT%
                git checkout develop
            '''
            bat '''
                cd %WIN_COMMUNITY_ROOT%
                git checkout develop
            '''
        }
    }
    bat '''
        cd %WIN_INTERNAL_ROOT%
haoranc's avatar
haoranc 已提交
243
        git pull  origin  ''' + env.CHANGE_TARGET + '''
T
tangfangzhi 已提交
244 245 246 247
    '''
    bat '''
        cd %WIN_COMMUNITY_ROOT%
        git remote prune origin
haoranc's avatar
haoranc 已提交
248
        git pull  origin  ''' + env.CHANGE_TARGET + '''
T
tangfangzhi 已提交
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
    '''
    bat '''
        cd %WIN_INTERNAL_ROOT%
        git branch
        git log -5
    '''
    bat '''
        cd %WIN_COMMUNITY_ROOT%
        git branch
        git log -5
    '''
    script {
        if (env.CHANGE_URL =~ /\/TDengine\//) {
            bat '''
                echo "match /TDengine/ repository"
                cd %WIN_COMMUNITY_ROOT%
                git fetch origin +refs/pull/%CHANGE_ID%/merge
                git checkout -qf FETCH_HEAD
                git log -5
            '''
        } else if (env.CHANGE_URL =~ /\/TDinternal\//) {
            bat '''
                echo "match /TDinternal/ repository"
                cd %WIN_INTERNAL_ROOT%
                git fetch origin +refs/pull/%CHANGE_ID%/merge
                git checkout -qf FETCH_HEAD
                git log -5
            '''
        } else {
            bat '''
                echo "unmatched reposiotry %CHANGE_URL%"
            '''
        }
    }
    bat '''
        cd %WIN_COMMUNITY_ROOT%
        git submodule update --init --recursive
    '''
    /*bat '''
        cd %WIN_CONNECTOR_ROOT%
        git branch
        git reset --hard
        git pull
    '''
    bat '''
        cd %WIN_CONNECTOR_ROOT%
        git log -5
    '''*/
}
def pre_test_build_win() {
    bat '''
        echo "building ..."
        time /t
        cd %WIN_INTERNAL_ROOT%
        mkdir debug
        cd debug
        time /t
        call "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Auxiliary\\Build\\vcvarsall.bat" x64
        set CL=/MP8
        echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> cmake"
        time /t
        cmake .. -G "NMake Makefiles JOM" || exit 7
        echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> jom -j 6"
        time /t
        jom -j 6 || exit 8
        time /t
    '''
    return 1
}
318
pipeline {
T
tangfangzhi 已提交
319
    agent none
320 321
    options { skipDefaultCheckout() }
    environment{
322
        WKDIR = '/var/data/jenkins/workspace'
T
tangfangzhi 已提交
323 324 325
        WK = '/var/data/jenkins/workspace/TDinternal'
        WKC = '/var/data/jenkins/workspace/TDinternal/community'
        LOGDIR = '/var/data/jenkins/workspace/log'
326 327 328
    }
    stages {
        stage('run test') {
T
tangfangzhi 已提交
329 330 331 332 333 334 335
            options { skipDefaultCheckout() }
            when {
                allOf {
                    changeRequest()
                    not { expression { env.CHANGE_BRANCH =~ /docs\// }}
                }
            }
T
tangfangzhi 已提交
336
            parallel {
T
tangfangzhi 已提交
337 338
                stage ('build arm64') {
                    agent {label " worker07_arm64 || worker09_arm64 "}
T
tangfangzhi 已提交
339 340
                    steps {
                        timeout(time: 20, unit: 'MINUTES') {
341
                            pre_test_arm64()
T
tangfangzhi 已提交
342 343
                            script {
                                sh '''
T
tangfangzhi 已提交
344
                                    echo "arm64 build done"
T
tangfangzhi 已提交
345 346 347 348 349 350
                                    date
                                '''
                            }
                        }
                    }
                }
T
tangfangzhi 已提交
351
                stage ('build Mac') {
T
tangfangzhi 已提交
352 353 354 355 356 357
                    agent {label " Mac_catalina "}
                    steps {
                        timeout(time: 20, unit: 'MINUTES') {
                            pre_test_mac()
                            script {
                                sh '''
T
tangfangzhi 已提交
358
                                    echo "Mac build done"
T
tangfangzhi 已提交
359 360 361 362 363 364
                                    date
                                '''
                            }
                        }
                    }
                }
T
tangfangzhi 已提交
365 366 367 368 369 370 371 372 373
                stage('build win') {
                    agent {label " windows10_05 || windows10_06 "}
                    environment{
                        WIN_INTERNAL_ROOT="C:\\workspace\\${env.EXECUTOR_NUMBER}\\TDinternal"
                        WIN_COMMUNITY_ROOT="C:\\workspace\\${env.EXECUTOR_NUMBER}\\TDinternal\\community"
                        WIN_SYSTEM_TEST_ROOT="C:\\workspace\\${env.EXECUTOR_NUMBER}\\TDinternal\\community\\tests\\system-test"
                        WIN_CONNECTOR_ROOT="C:\\workspace\\${env.EXECUTOR_NUMBER}\\taos-connector-python"
                    }
                    steps {
T
tangfangzhi 已提交
374
                        timeout(time: 20, unit: 'MINUTES') {
T
tangfangzhi 已提交
375 376 377 378 379
                            pre_test_win()
                            pre_test_build_win()
                        }
                    }
                }
T
tangfangzhi 已提交
380
                stage('run cases') {
T
tangfangzhi 已提交
381
                    agent {label " worker01 || worker02 "}
T
tangfangzhi 已提交
382 383 384
                    steps {
                        sh '''
                            date
T
tangfangzhi 已提交
385
                            pwd
T
tangfangzhi 已提交
386 387
                            hostname
                        '''
T
tangfangzhi 已提交
388 389 390 391 392 393 394 395 396
                        timeout(time: 15, unit: 'MINUTES') {
                            pre_test()
                            script {
                                sh '''
                                    echo "Linux build done"
                                    date
                                '''
                            }
                        }
T
tangfangzhi 已提交
397
                        catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
T
tangfangzhi 已提交
398 399 400 401 402 403 404 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
                            timeout(time: 60, unit: 'MINUTES') {
                                script {
                                    def extra_param = ""
                                    def log_server_file = "/home/log_server.json"
                                    def timeout_cmd = ""
                                    if (fileExists(log_server_file)) {
                                        def log_server_enabled = sh (
                                            script: 'jq .enabled ' + log_server_file,
                                            returnStdout: true
                                        ).trim()
                                        def timeout_param = sh (
                                            script: 'jq .timeout ' + log_server_file,
                                            returnStdout: true
                                        ).trim()
                                        if (timeout_param != "null" &&  timeout_param != "0") {
                                            timeout_cmd = "timeout " + timeout_param
                                        }
                                        if (log_server_enabled == "1") {
                                            def log_server = sh (
                                                script: 'jq .server ' + log_server_file + ' | sed "s/\\\"//g"',
                                                returnStdout: true
                                            ).trim()
                                            if (log_server != "null" && log_server != "") { 
                                                extra_param = "-w " + log_server
                                            }
                                        }
                                    }
                                    sh '''
                                        date
                                        cd ${WKC}/tests/parallel_test
                                        ''' + timeout_cmd + ''' time ./run.sh -m /home/m.json -t cases.task -l ${LOGDIR} -b ${BRANCH_NAME} ''' + extra_param + '''
                                        date
                                        hostname
                                    '''
                                }
T
tangfangzhi 已提交
433
                            }
T
tangfangzhi 已提交
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 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520
                }
            }    
        }
    }
    post {
        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>
                        </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>
                        </body>
                    </html>""",
                to: "${env.CHANGE_AUTHOR_EMAIL}",
                from: "support@taosdata.com"
            )
        }
    }
}