Jenkinsfile 6.4 KB
Newer Older
L
liuyq-617 已提交
1
import hudson.model.Result
2
import hudson.model.*;
L
liuyq-617 已提交
3
import jenkins.model.CauseOfInterruption
4 5 6
node {
}

Y
Yiqing Liu 已提交
7 8
def skipbuild=0
def win_stop=0
L
liuyq-617 已提交
9

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

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

L
recover  
liuyq-617 已提交
21 22 23 24 25 26 27 28 29 30 31 32 33 34
    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)
}
35
def pre_test(){
L
liuyq-617 已提交
36
    sh'hostname'
L
liuyq-617 已提交
37 38 39
    sh '''
    sudo rmtaos || echo "taosd has not installed"
    '''
L
liuyq-617 已提交
40
    sh '''
L
fix  
liuyq-617 已提交
41 42
    killall -9 taosd ||echo "no taosd running"
    killall -9 gdb || echo "no gdb running"
L
liuyq-617 已提交
43
    killall -9 python3.8 || echo "no python program running"
L
liuyq-617 已提交
44
    cd ${WKC}
L
fix  
liuyq-617 已提交
45 46 47
    '''
    script {
      if (env.CHANGE_TARGET == 'master') {
L
fix  
liuyq-617 已提交
48
        sh '''
L
liuyq-617 已提交
49
        cd ${WKC}
L
fix  
liuyq-617 已提交
50 51
        git checkout master
        '''
L
fix  
liuyq-617 已提交
52
        }
53
      else if(env.CHANGE_TARGET == '2.0'){
L
fix  
liuyq-617 已提交
54
        sh '''
L
liuyq-617 已提交
55
        cd ${WKC}
56
        git checkout 2.0
L
fix  
liuyq-617 已提交
57
        '''
L
liuyq-617 已提交
58 59 60
      }
      else if(env.CHANGE_TARGET == '3.0'){
        sh '''
L
liuyq-617 已提交
61
        cd ${WKC}
L
liuyq-617 已提交
62 63
        git checkout 3.0
        '''
L
fix  
liuyq-617 已提交
64
      } 
65 66
      else{
        sh '''
L
liuyq-617 已提交
67
        cd ${WKC}
68 69 70
        git checkout develop
        '''
      }
L
fix  
liuyq-617 已提交
71 72
    }
    sh'''
L
liuyq-617 已提交
73
    cd ${WKC}
L
liuyq-617 已提交
74
    git pull >/dev/null
L
liuyq-617 已提交
75
    git fetch origin +refs/pull/${CHANGE_ID}/merge
76
    git checkout -qf FETCH_HEAD
77 78
    export TZ=Asia/Harbin
    date
L
liuyq-617 已提交
79
    rm -rf debug
80 81 82
    mkdir debug
    cd debug
    cmake .. > /dev/null
H
Hongze Cheng 已提交
83
    make -j4> /dev/null
L
liuyq-617 已提交
84

L
liuyq-617 已提交
85
    '''
86 87
    return 1
}
L
liuyq-617 已提交
88

Y
Yiqing Liu 已提交
89
pipeline {
L
liuyq-617 已提交
90
  agent none
91
  options { skipDefaultCheckout() } 
L
liuyq-617 已提交
92 93
  environment{
      WK = '/var/lib/jenkins/workspace/TDinternal'
L
liuyq-617 已提交
94
      WKC= '/var/lib/jenkins/workspace/TDengine'
L
liuyq-617 已提交
95
  }
Y
Yiqing Liu 已提交
96
  stages {
L
change  
liuyq-617 已提交
97
      stage('pre_build'){
L
liuyq-617 已提交
98
          agent{label 'slave3_0'}
99
          options { skipDefaultCheckout() } 
L
liuyq-617 已提交
100 101 102
          when {
              changeRequest()
          }
103
          steps {
L
change  
liuyq-617 已提交
104 105 106 107
            script{
              abort_previous()
              abortPreviousBuilds()
            }
L
liuyq-617 已提交
108 109 110 111 112 113 114 115 116 117 118
            timeout(time: 45, unit: 'MINUTES'){
              pre_test()
              sh'''
              cd ${WKC}/tests
              ./test-all.sh b1fq
              '''
              sh'''
              cd ${WKC}/debug
              ctest
              '''
            }
119 120
          }
      }
L
liuyq-617 已提交
121
  }
L
liuyq-617 已提交
122
  post {  
123 124
        success {
            emailext (
125 126
                subject: "PR-result: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' SUCCESS",
                body: """<!DOCTYPE html>
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
                <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">
142
                                    <li>构建名称>>分支:${env.BRANCH_NAME}</li>
143 144
                                    <li>构建结果:<span style="color:green"> Successful </span></li>
                                    <li>构建编号:${BUILD_NUMBER}</li>
145
                                    <li>触发用户:${env.CHANGE_AUTHOR}</li>
L
fix  
liuyq-617 已提交
146
                                    <li>提交信息:${env.CHANGE_TITLE}</li>
147 148
                                    <li>构建地址:<a href=${BUILD_URL}>${BUILD_URL}</a></li>
                                    <li>构建日志:<a href=${BUILD_URL}console>${BUILD_URL}console</a></li>
149
                                    
150 151 152 153 154 155
                                </div>
                                </ul>
                            </td>
                        </tr>
                    </table></font>
                </body>
156
                </html>""",
L
liuyq-617 已提交
157
                to: "${env.CHANGE_AUTHOR_EMAIL}",
158 159 160 161 162
                from: "support@taosdata.com"
            )
        }
        failure {
            emailext (
163 164
                subject: "PR-result: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' FAIL",
                body: """<!DOCTYPE html>
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
                <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">
180
                                    <li>构建名称>>分支:${env.BRANCH_NAME}</li>
L
liuyq-617 已提交
181
                                    <li>构建结果:<span style="color:red"> Failure </span></li>
182
                                    <li>构建编号:${BUILD_NUMBER}</li>
183
                                    <li>触发用户:${env.CHANGE_AUTHOR}</li>
L
fix  
liuyq-617 已提交
184
                                    <li>提交信息:${env.CHANGE_TITLE}</li>
185 186
                                    <li>构建地址:<a href=${BUILD_URL}>${BUILD_URL}</a></li>
                                    <li>构建日志:<a href=${BUILD_URL}console>${BUILD_URL}console</a></li>
187
                                    
188 189 190 191 192 193
                                </div>
                                </ul>
                            </td>
                        </tr>
                    </table></font>
                </body>
194
                </html>""",
L
liuyq-617 已提交
195
                to: "${env.CHANGE_AUTHOR_EMAIL}",
196 197 198
                from: "support@taosdata.com"
            )
        }
L
liuyq-617 已提交
199
    } 
X
xiaolei li 已提交
200
}