Jenkinsfile2 6.9 KB
Newer Older
L
liuyq-617 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
import hudson.model.Result
import hudson.model.*;
import jenkins.model.CauseOfInterruption
node {
}

def skipbuild=0
def win_stop=0

def abortPreviousBuilds() {
  def currentJobName = env.JOB_NAME
  def currentBuildNumber = env.BUILD_NUMBER.toInteger()
  def jobs = Jenkins.instance.getItemByFullName(currentJobName)
  def builds = jobs.getBuilds()

  for (build in builds) {
    if (!build.isBuilding()) {
      continue;
    }

    if (currentBuildNumber == build.getNumber().toInteger()) {
      continue;
    }

    build.doKill()    //doTerm(),doKill(),doTerm()
  }
}
//  abort previous build
abortPreviousBuilds()
def abort_previous(){
  def buildNumber = env.BUILD_NUMBER as int
  if (buildNumber > 1) milestone(buildNumber - 1)
  milestone(buildNumber)
}
def pre_test(){
    sh'hostname'
    sh '''
T
tangfangzhi 已提交
38
    date
L
liuyq-617 已提交
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
    sudo rmtaos || echo "taosd has not installed"
    '''
    sh '''
    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}
    '''
    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 == '3.0'){
        sh '''
        cd ${WKC}
        git checkout 3.0
64
        [ -d contrib/bdb ] && cd contrib/bdb && git clean -fxd && cd ../..
L
liuyq-617 已提交
65
        '''
66
      }
L
liuyq-617 已提交
67 68 69 70 71 72 73 74 75 76 77 78
      else{
        sh '''
        cd ${WKC}
        git checkout develop
        '''
      }
    }
    sh'''
    cd ${WKC}
    git pull >/dev/null
    git fetch origin +refs/pull/${CHANGE_ID}/merge
    git checkout -qf FETCH_HEAD
79
    git submodule update --init --recursive
80 81 82
    '''
    sh'''
    cd ${WKC}
L
liuyq-617 已提交
83 84 85 86 87 88 89 90
    export TZ=Asia/Harbin
    date
    rm -rf debug
    mkdir debug
    cd debug
    cmake .. > /dev/null
    make -j4> /dev/null
    '''
T
tangfangzhi 已提交
91 92 93 94 95 96
    sh'''
    cd ${WKPY}
    git reset --hard
    git pull
    pip3 install .
    '''
L
liuyq-617 已提交
97 98 99 100 101 102 103 104 105
    return 1
}

pipeline {
  agent none
  options { skipDefaultCheckout() } 
  environment{
      WK = '/var/lib/jenkins/workspace/TDinternal'
      WKC= '/var/lib/jenkins/workspace/TDengine'
T
tangfangzhi 已提交
106
      WKPY= '/var/lib/jenkins/workspace/taos-connector-python'
L
liuyq-617 已提交
107 108 109
  }
  stages {
      stage('pre_build'){
T
tangfangzhi 已提交
110
          agent{label " slave3_0 || slave15 || slave16 || slave17 "}
L
liuyq-617 已提交
111 112 113 114 115 116 117 118 119 120 121 122
          options { skipDefaultCheckout() } 
          when {
              changeRequest()
          }
          steps {
            script{
              abort_previous()
              abortPreviousBuilds()
            }
            timeout(time: 45, unit: 'MINUTES'){
              pre_test()
              sh'''
T
tangfangzhi 已提交
123
              cd ${WKC}/debug
124
              ctest -VV
L
liuyq-617 已提交
125 126
              '''
              sh'''
T
tangfangzhi 已提交
127 128 129 130 131
              export LD_LIBRARY_PATH=${WKC}/debug/build/lib
              cd ${WKC}/tests/system-test
              ./fulltest.sh
              '''
              sh'''
T
tangfangzhi 已提交
132 133
              cd ${WKC}/tests
              ./test-all.sh b1fq
L
liuyq-617 已提交
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 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
              '''
            }
          }
      }
  }
  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></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"
            )
        }
    } 
}