Jenkinsfile2 14.3 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 10
    sh '''
        hostname
        date
        '''
11 12 13
    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"
14
        git reset --hard >/dev/null
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
    '''
    script {
        if (env.CHANGE_TARGET == 'master') {
            sh '''
                cd ${WKC}
                git checkout master
            '''
        } else if (env.CHANGE_TARGET == '2.0') {
            sh '''
                cd ${WKC}
                git checkout 2.0
            '''
        } else if (env.CHANGE_TARGET == '2.4') {
            sh '''
                cd ${WKC}
                git checkout 2.4
            '''
        } else {
            sh '''
                cd ${WKC}
                git checkout develop
            '''
        }
    }
39
    sh '''
40
        cd ${WKC}
41
        git reset --hard
42 43 44 45 46
        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
        git fetch origin +refs/pull/${CHANGE_ID}/merge
        git checkout -qf FETCH_HEAD
47
        git reset --hard
T
tangfangzhi 已提交
48
        git clean -dfx
49
        git submodule update --init --recursive --remote
50 51
        git submodule update --init --recursive
        cd ${WK}
52 53 54 55 56
        git reset --hard
    '''
    sh '''
        cd ${WKCT}
        git reset --hard
57 58 59 60 61 62
    '''
    script {
        if (env.CHANGE_TARGET == 'master') {
            sh '''
                cd ${WK}
                git checkout master
63 64
                cd ${WKCT}
                git checkout master
65 66 67 68 69
            '''
        } else if (env.CHANGE_TARGET == '2.0') {
            sh '''
                cd ${WK}
                git checkout 2.0
70 71
                cd ${WKCT}
                git checkout 2.0
72 73 74 75 76
            '''
        } else if (env.CHANGE_TARGET == '2.4') {
            sh '''
                cd ${WK}
                git checkout 2.4
77 78
                cd ${WKCT}
                git checkout 2.4
79 80 81 82 83
            '''
        } else {
            sh '''
                cd ${WK}
                git checkout develop
84 85
                cd ${WKCT}
                git checkout develop
86 87 88 89
            '''
        }
    }
    sh '''
90
        export TZ=Asia/Harbin
91 92
        cd ${WK}
        git pull >/dev/null
T
tangfangzhi 已提交
93
        git clean -dfx
94 95 96 97
        cd ${WKCT}
        git pull >/dev/null
        git clean -dfx
        date
98 99 100 101 102 103 104 105
    '''
}
def pre_test() {
    sync_source()
    sh '''
        cd ${WK}
        mkdir -p debug
        cd debug
T
tangfangzhi 已提交
106 107
        go env -w GOPROXY=https://goproxy.cn,direct
        go env -w GO111MODULE=on
108
        cmake .. -DBUILD_HTTP=false -DBUILD_TOOLS=true > /dev/null
T
tangfangzhi 已提交
109 110 111 112 113 114 115 116 117 118 119 120 121 122
        make -j8 >/dev/null
    '''
    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
123 124 125 126 127 128 129
    '''
    return 1
}
pipeline {
    agent {label " dispatcher "}
    options { skipDefaultCheckout() }
    environment{
T
tangfangzhi 已提交
130 131
        WK = '/var/data/jenkins/workspace/TDinternal'
        WKC = '/var/data/jenkins/workspace/TDinternal/community'
132
        WKCT = '/var/data/jenkins/workspace/TDinternal/community/tests'
T
tangfangzhi 已提交
133
        LOGDIR = '/var/data/jenkins/workspace/log'
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
    }
    stages {
        stage ('pre_build') {
            steps {
                sh '''
                    date
                    pwd
                    env
                    hostname
                '''
            }
        }
        stage ('Parallel build stage') {
            //only build pr
            options { skipDefaultCheckout() }
            when {
                allOf {
                    changeRequest()
                    not { expression { env.CHANGE_BRANCH =~ /docs\// }}
                }
            }
            parallel {
                stage ('dispatcher sync source') {
                    steps {
T
tangfangzhi 已提交
158 159
                        timeout(time: 20, unit: 'MINUTES') {
                            sync_source()
160 161 162 163 164 165 166 167 168 169 170 171
                            script {
                                sh '''
                                    echo "dispatcher ready"
                                    date
                                '''
                            }
                        }
                    }
                }
                stage ('build worker01') {
                    agent {label " worker01 "}
                    steps {
T
tangfangzhi 已提交
172 173
                        timeout(time: 20, unit: 'MINUTES') {
                            pre_test()
174 175 176 177 178 179 180 181 182 183 184 185
                            script {
                                sh '''
                                    echo "worker01 build done"
                                    date
                                '''
                            }
                        }
                    }
                }
                stage ('build worker02') {
                    agent {label " worker02 "}
                    steps {
T
tangfangzhi 已提交
186 187
                        timeout(time: 20, unit: 'MINUTES') {
                            pre_test()
188 189 190 191 192 193 194 195 196 197 198 199
                            script {
                                sh '''
                                    echo "worker02 build done"
                                    date
                                '''
                            }
                        }
                    }
                }
                stage ('build worker03') {
                    agent {label " worker03 "}
                    steps {
T
tangfangzhi 已提交
200 201
                        timeout(time: 20, unit: 'MINUTES') {
                            pre_test()
202 203 204 205 206 207 208 209 210 211 212 213
                            script {
                                sh '''
                                    echo "worker03 build done"
                                    date
                                '''
                            }
                        }
                    }
                }
                stage ('build worker04') {
                    agent {label " worker04 "}
                    steps {
T
tangfangzhi 已提交
214 215
                        timeout(time: 20, unit: 'MINUTES') {
                            pre_test()
216 217 218 219 220 221 222 223 224 225 226 227
                            script {
                                sh '''
                                    echo "worker04 build done"
                                    date
                                '''
                            }
                        }
                    }
                }
                stage ('build worker05') {
                    agent {label " worker05 "}
                    steps {
T
tangfangzhi 已提交
228 229
                        timeout(time: 20, unit: 'MINUTES') {
                            pre_test()
230 231 232 233 234 235 236 237 238 239 240 241
                            script {
                                sh '''
                                    echo "worker05 build done"
                                    date
                                '''
                            }
                        }
                    }
                }
            }
        }
        stage('run test') {
T
tangfangzhi 已提交
242 243 244 245 246 247 248
            options { skipDefaultCheckout() }
            when {
                allOf {
                    changeRequest()
                    not { expression { env.CHANGE_BRANCH =~ /docs\// }}
                }
            }
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
            parallel {
                stage ('build worker06_arm64') {
                    agent {label " worker06_arm64 "}
                    steps {
                        timeout(time: 20, unit: 'MINUTES') {
                            pre_test()
                            script {
                                sh '''
                                    echo "worker06_arm64 build done"
                                    date
                                '''
                            }
                        }
                    }
                }
                stage ('build worker07_arm64') {
                    agent {label " worker07_arm64 "}
                    steps {
                        timeout(time: 20, unit: 'MINUTES') {
                            pre_test()
                            script {
                                sh '''
                                    echo "worker07_arm64 build done"
                                    date
                                '''
                            }
                        }
                    }
                }
                stage ('build Mac_catalina ') {
                    agent {label " Mac_catalina "}
                    steps {
                        timeout(time: 20, unit: 'MINUTES') {
                            pre_test_mac()
                            script {
                                sh '''
                                    echo "Mac_catalina build done"
                                    date
                                '''
                            }
                        }
                    }
                }
                stage('run cases') {
                    steps {
                        sh '''
                            date
                            hostname
                        '''
T
tangfangzhi 已提交
298 299 300 301 302 303 304 305 306 307
                        catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
                            timeout(time: 20, unit: 'MINUTES') {
                                sh '''
                                    date
                                    cd ${WKC}/tests/parallel_test
                                    time ./run.sh -m m.json -t cases.task -l ${LOGDIR} -b ${BRANCH_NAME}
                                    date
                                    hostname
                                '''
                            }
T
tangfangzhi 已提交
308 309
                        }
                    }
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
                }
            }    
        }
    }
    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"
            )
        }
    }
}