Jenkinsfile2 10.9 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(){
T
tangfangzhi 已提交
36
    sh 'hostname'
L
liuyq-617 已提交
37
    sh '''
T
tangfangzhi 已提交
38 39
        date
        sudo rmtaos || echo "taosd has not installed"
L
liuyq-617 已提交
40 41
    '''
    sh '''
T
tangfangzhi 已提交
42 43 44 45
        killall -9 taosd ||echo "no taosd running"
        killall -9 gdb || echo "no gdb running"
        killall -9 python3.8 || echo "no python program running"
        cd ${WKC}
L
liuyq-617 已提交
46 47
    '''
    script {
T
tangfangzhi 已提交
48 49
        if (env.CHANGE_TARGET == 'master') {
            sh '''
T
tangfangzhi 已提交
50 51
                cd ${WK}
                git checkout master
T
tangfangzhi 已提交
52 53 54 55 56
                cd ${WKC}
                git checkout master
            '''
        } else if(env.CHANGE_TARGET == '2.0') {
            sh '''
T
tangfangzhi 已提交
57 58
                cd ${WK}
                git checkout 2.0
T
tangfangzhi 已提交
59 60 61 62 63
                cd ${WKC}
                git checkout 2.0
            '''
        } else if(env.CHANGE_TARGET == '3.0') {
            sh '''
T
tangfangzhi 已提交
64 65
                cd ${WK}
                git checkout 3.0
T
tangfangzhi 已提交
66 67 68 69 70 71
                cd ${WKC}
                git checkout 3.0
                [ -d contrib/bdb ] && cd contrib/bdb && git clean -fxd && cd ../..
            '''
        } 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 85 86 87 88 89 90 91 92 93 94 95 96 97
    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
        '''
    } 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
        '''
    } else {
        sh '''
            echo "unmatched reposiotry ${CHANGE_URL}"
        '''
    }
T
tangfangzhi 已提交
98
    sh '''
L
liuyq-617 已提交
99
        cd ${WKC}
T
tangfangzhi 已提交
100 101 102
        git submodule update --init --recursive
    '''
    sh '''
T
tangfangzhi 已提交
103
        cd ${WK}
T
tangfangzhi 已提交
104 105 106 107 108 109 110
        export TZ=Asia/Harbin
        date
        rm -rf debug
        mkdir debug
        cd debug
        cmake .. > /dev/null
        make -j4> /dev/null
111
    '''
T
tangfangzhi 已提交
112 113 114 115 116
    sh '''
        cd ${WKPY}
        git reset --hard
        git pull
        pip3 install .
L
liuyq-617 已提交
117
    '''
T
tangfangzhi 已提交
118 119 120 121 122 123 124 125 126
    return 1
}
def pre_test_win(){
    bat '''
        hostname
        date /t
        time /t
        taskkill /f /t /im python.exe
        taskkill /f /t /im bash.exe
127 128
        cd C:\\workspace\\%EXECUTOR_NUMBER%\\TDengine
        rd /s /Q C:\\workspace\\%EXECUTOR_NUMBER%\\TDengine\\debug
T
tangfangzhi 已提交
129 130 131
        exit 0
    '''
    bat '''
132
        cd C:\\workspace\\%EXECUTOR_NUMBER%\\TDengine
T
tangfangzhi 已提交
133 134 135 136 137 138 139
        git reset --hard
        git fetch || git fetch
        git checkout -f
    '''
    script {
        if (env.CHANGE_TARGET == 'master') {
            bat '''
140
                cd C:\\workspace\\%EXECUTOR_NUMBER%\\TDengine
T
tangfangzhi 已提交
141 142 143 144
                git checkout master
            '''
        } else if(env.CHANGE_TARGET == '2.0') {
            bat '''
145
                cd C:\\workspace\\%EXECUTOR_NUMBER%\\TDengine
T
tangfangzhi 已提交
146 147 148 149
                git checkout 2.0
            '''
        } else if(env.CHANGE_TARGET == '3.0') {
            bat '''
150
                cd C:\\workspace\\%EXECUTOR_NUMBER%\\TDengine
T
tangfangzhi 已提交
151 152 153 154
                git checkout 3.0
            '''
        } else {
            bat '''
155
                cd C:\\workspace\\%EXECUTOR_NUMBER%\\TDengine
T
tangfangzhi 已提交
156 157 158 159 160
                git checkout develop
            '''
        }
    }
    bat '''
161
        cd C:\\workspace\\%EXECUTOR_NUMBER%\\TDengine
T
tangfangzhi 已提交
162 163 164 165 166 167 168 169 170 171
        git branch
        git pull || git pull
        git fetch origin +refs/pull/%CHANGE_ID%/merge
        git checkout -qf FETCH_HEAD
    '''
}
def pre_test_build_win() {
    bat '''
        echo "building ..."
        time /t
172
        cd C:\\workspace\\%EXECUTOR_NUMBER%\\TDengine
T
tangfangzhi 已提交
173 174 175 176
        mkdir debug
        cd debug
        call "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Auxiliary\\Build\\vcvarsall.bat" x64
        set CL=/MP8
177
        cmake .. -G "NMake Makefiles JOM"
T
tangfangzhi 已提交
178
        jom -j 4 || exit 8
T
tangfangzhi 已提交
179
        time /t
T
tangfangzhi 已提交
180
    '''
L
liuyq-617 已提交
181 182 183 184
    return 1
}

pipeline {
T
tangfangzhi 已提交
185 186 187 188
    agent none
    options { skipDefaultCheckout() } 
    environment{
        WK = '/var/lib/jenkins/workspace/TDinternal'
T
tangfangzhi 已提交
189 190
        WKC = '/var/lib/jenkins/workspace/TDinternal/community'
        WKPY = '/var/lib/jenkins/workspace/taos-connector-python'
T
tangfangzhi 已提交
191 192 193 194 195 196 197 198 199 200 201 202 203
    }
    stages {
        stage('run test') {
            parallel {
                stage('linux test') {
                    agent{label " slave3_0 || slave15 || slave16 || slave17 "}
                    options { skipDefaultCheckout() } 
                    when {
                        changeRequest()
                    }
                    steps {
                        timeout(time: 45, unit: 'MINUTES'){
                            pre_test()
T
tangfangzhi 已提交
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
                            script {
                                if (env.CHANGE_URL =~ /\/TDengine\//) {
                                    sh '''
                                        cd ${WK}/debug
                                        ctest -VV
                                    '''
                                    sh '''
                                        export LD_LIBRARY_PATH=${WK}/debug/build/lib
                                        cd ${WKC}/tests/system-test
                                        ./fulltest.sh
                                    '''
                                } else if (env.CHANGE_URL =~ /\/TDinternal\//) {
                                    sh '''
                                        cd ${WKC}/debug
                                        ctest -VV
                                    '''
                                    sh '''
                                        export LD_LIBRARY_PATH=${WKC}/debug/build/lib
                                        cd ${WKC}/tests/system-test
                                        ./fulltest.sh
                                    '''
                                } else {
                                    sh '''
                                        echo "unmatched reposiotry ${CHANGE_URL}"
                                    '''
                                }
T
tangfangzhi 已提交
230
                            }
T
tangfangzhi 已提交
231 232 233 234 235 236 237
                            sh '''
                                cd ${WKC}/tests
                                ./test-all.sh b1fq
                            '''
                        }
                    }
                }
L
liuyq-617 已提交
238
            }
T
tangfangzhi 已提交
239 240 241
        }
    }
    post {  
L
liuyq-617 已提交
242 243 244 245 246 247 248 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 318 319
        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"
            )
        }
    } 
}