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

def skipbuild=0
def win_stop=0

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

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

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

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

pipeline {
T
tangfangzhi 已提交
253 254 255
    agent none
    options { skipDefaultCheckout() } 
    environment{
T
tangfangzhi 已提交
256
        WKDIR = '/var/lib/jenkins/workspace'
T
tangfangzhi 已提交
257
        WK = '/var/lib/jenkins/workspace/TDinternal'
T
tangfangzhi 已提交
258 259
        WKC = '/var/lib/jenkins/workspace/TDinternal/community'
        WKPY = '/var/lib/jenkins/workspace/taos-connector-python'
T
tangfangzhi 已提交
260 261 262 263
    }
    stages {
        stage('run test') {
            parallel {
T
tangfangzhi 已提交
264 265 266 267 268 269 270
                stage('windows test') {
                    agent{label " windows10_01 || windows10_02 || windows10_03 || windows10_04 "}
                    steps {
                        pre_test_win()
                        pre_test_build_win()
                    }
                }
T
tangfangzhi 已提交
271
                stage('linux test') {
T
tangfangzhi 已提交
272
                    agent{label " worker03 || slave215 || slave217 || slave219 "}
T
tangfangzhi 已提交
273 274 275 276 277
                    options { skipDefaultCheckout() } 
                    when {
                        changeRequest()
                    }
                    steps {
T
tangfangzhi 已提交
278
                        timeout(time: 40, unit: 'MINUTES'){
T
tangfangzhi 已提交
279
                            pre_test()
T
tangfangzhi 已提交
280
                            script {
281 282 283 284 285 286
                                sh '''
                                    cd ${WKC}/tests/parallel_test
                                    date
                                    time ./container_build.sh -w ${WKDIR} -t 8 -e
                                    rm -f /tmp/cases.task
                                    ./collect_cases.sh -e
T
tangfangzhi 已提交
287 288
                                '''
                                sh '''
289
                                    cd ${WKC}/tests/parallel_test
T
tangfangzhi 已提交
290
                                    export DEFAULT_RETRY_TIME=2
291
                                    date
292
                                    timeout 2100 time ./run.sh -e -m /home/m.json -t /tmp/cases.task -b ${BRANCH_NAME}_${BUILD_ID} -l ${WKDIR}/log -o 480
293
                                '''
T
tangfangzhi 已提交
294
                            }
T
tangfangzhi 已提交
295 296 297
                        }
                    }
                }
L
liuyq-617 已提交
298
            }
T
tangfangzhi 已提交
299 300 301
        }
    }
    post {  
L
liuyq-617 已提交
302 303 304 305 306 307 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
        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"
            )
        }
    } 
}