Jenkinsfile 10.3 KB
Newer Older
1 2
#!/usr/bin/env groovy

M
milvus-ci-robot 已提交
3
String cron_timezone = "TZ=Asia/Shanghai"
M
milvus-ci-robot 已提交
4
String cron_string = BRANCH_NAME == "master" ? "H 0 * * * " : ""
M
milvus-ci-robot 已提交
5

T
add ci  
test 已提交
6 7 8
pipeline {
    agent none

M
milvus-ci-robot 已提交
9
    triggers {
M
milvus-ci-robot 已提交
10 11
        cron """${cron_timezone}
            ${cron_string}"""
M
milvus-ci-robot 已提交
12
    }
13

T
add ci  
test 已提交
14 15 16 17 18
    options {
        timestamps()
    }

    parameters{
Q
quicksilver 已提交
19
        choice choices: ['Release', 'Debug'], description: 'Build Type', name: 'BUILD_TYPE'
M
milvus-ci-robot 已提交
20
        string defaultValue: 'registry.zilliz.com', description: 'DOCKER REGISTRY URL', name: 'DOKCER_REGISTRY_URL', trim: true
T
add ci  
test 已提交
21
        string defaultValue: 'ba070c98-c8cc-4f7c-b657-897715f359fc', description: 'DOCKER CREDENTIALS ID', name: 'DOCKER_CREDENTIALS_ID', trim: true
M
milvus-ci-robot 已提交
22
        string defaultValue: 'http://192.168.1.201/artifactory/milvus', description: 'JFROG ARTFACTORY URL', name: 'JFROG_ARTFACTORY_URL', trim: true
M
milvus-ci-robot 已提交
23
        string defaultValue: '1a527823-d2b7-44fd-834b-9844350baf14', description: 'JFROG CREDENTIALS ID', name: 'JFROG_CREDENTIALS_ID', trim: true
T
add ci  
test 已提交
24 25 26 27
    }

    environment {
        PROJECT_NAME = "milvus"
28 29
        MILVUS_ROOT_PATH="/var/lib"
        MILVUS_INSTALL_PREFIX="${env.MILVUS_ROOT_PATH}/${env.PROJECT_NAME}"
T
add ci  
test 已提交
30
        LOWER_BUILD_TYPE = params.BUILD_TYPE.toLowerCase()
Q
quicksilver 已提交
31 32
        SEMVER = "${BRANCH_NAME.contains('/') ? BRANCH_NAME.substring(BRANCH_NAME.lastIndexOf('/') + 1) : BRANCH_NAME}"
        PIPELINE_NAME = "${env.JOB_NAME.contains('/') ? env.JOB_NAME.getAt(0..(env.JOB_NAME.indexOf('/') - 1)) : env.JOB_NAME}"
T
add ci  
test 已提交
33 34 35
    }

    stages {
36 37 38 39 40 41 42 43
        stage ('Milvus Build and Test') {
            matrix {
                agent none
                axes {
                    axis {
                        name 'OS_NAME'
                        values 'ubuntu18.04', 'centos7'
                    }
T
add ci  
test 已提交
44

45 46 47
                    axis {
                        name 'CPU_ARCH'
                        values 'amd64'
T
add ci  
test 已提交
48 49
                    }

50 51 52 53 54
                    axis {
                        name 'BINRARY_VERSION'
                        values 'gpu', 'cpu'
                    }
                }
55

Q
quicksilver 已提交
56
                stages {
Q
quicksilver 已提交
57
                    stage("Milvus CI") {
Q
quicksilver 已提交
58 59 60 61 62 63
                        environment {
                            PACKAGE_VERSION = VersionNumber([
                                versionNumberString : '${SEMVER}-${BINRARY_VERSION}-${OS_NAME}-${CPU_ARCH}-${LOWER_BUILD_TYPE}-${BUILD_DATE_FORMATTED, "yyyyMMdd"}-${BUILDS_TODAY}'
                            ]);
                            DOCKER_VERSION = "${SEMVER}-${BINRARY_VERSION}-${OS_NAME}-${LOWER_BUILD_TYPE}"
                        }
Q
quicksilver 已提交
64

Q
quicksilver 已提交
65
                        stages {
Q
quicksilver 已提交
66
                            stage('Run Build') {
Q
quicksilver 已提交
67 68
                                agent {
                                    kubernetes {
Q
quicksilver 已提交
69
                                        label "${OS_NAME}-${BINRARY_VERSION}-build"
Q
quicksilver 已提交
70 71 72
                                        defaultContainer 'jnlp'
                                        yamlFile "ci/jenkins/pod/milvus-${BINRARY_VERSION}-version-${OS_NAME}-build-env-pod.yaml"
                                    }
73
                                }
74

Q
quicksilver 已提交
75
                                stages {
Q
quicksilver 已提交
76
                                    stage('Build') {
Q
quicksilver 已提交
77 78 79 80 81
                                        steps {
                                            container("milvus-${BINRARY_VERSION}-build-env") {
                                                script {
                                                    load "${env.WORKSPACE}/ci/jenkins/step/build.groovy"
                                                }
82 83 84
                                            }
                                        }
                                    }
85

Q
quicksilver 已提交
86 87 88 89
                                    stage('Code Coverage') {
                                        steps {
                                            container("milvus-${BINRARY_VERSION}-build-env") {
                                                script {
Q
quicksilver 已提交
90 91 92 93 94
                                                    if ("${BINRARY_VERSION}" == "gpu") {
                                                        load "${env.WORKSPACE}/ci/jenkins/step/coverage.groovy"
                                                    } else {
                                                        echo "Skip Code Coverage"
                                                    }
Q
quicksilver 已提交
95
                                                }
96 97
                                            }
                                        }
T
add ci  
test 已提交
98
                                    }
99

Q
quicksilver 已提交
100 101 102 103 104 105
                                    stage('Upload Package') {
                                        steps {
                                            container("milvus-${BINRARY_VERSION}-build-env") {
                                                script {
                                                    load "${env.WORKSPACE}/ci/jenkins/step/package.groovy"
                                                }
106 107
                                            }
                                        }
T
add ci  
test 已提交
108 109
                                    }
                                }
Q
quicksilver 已提交
110 111 112 113 114 115

                                post {
                                    cleanup {
                                        deleteDir() /* clean up our workspace */
                                    }
                                }
T
add ci  
test 已提交
116 117
                            }

Q
quicksilver 已提交
118
                            stage('Publish docker images') {
Q
quicksilver 已提交
119 120
                                agent {
                                    kubernetes {
Q
quicksilver 已提交
121
                                        label "${OS_NAME}-${BINRARY_VERSION}-publish"
Q
quicksilver 已提交
122 123 124
                                        defaultContainer 'jnlp'
                                        yamlFile 'ci/jenkins/pod/docker-pod.yaml'
                                    }
125 126
                                }

Q
quicksilver 已提交
127 128 129 130 131 132 133
                                stages {
                                    stage('Publish') {
                                        steps {
                                            container('publish-images') {
                                                script {
                                                    load "${env.WORKSPACE}/ci/jenkins/step/publishImages.groovy"
                                                }
134 135 136 137
                                            }
                                        }
                                    }
                                }
Q
quicksilver 已提交
138 139 140 141 142 143

                                post {
                                    cleanup {
                                        deleteDir() /* clean up our workspace */
                                    }
                                }
T
add ci  
test 已提交
144 145
                            }

Q
quicksilver 已提交
146
                            stage('Deploy to Development') {
Q
quicksilver 已提交
147 148
                                environment {
                                    FROMAT_SEMVER = "${env.SEMVER}".replaceAll("\\.", "-")
Q
quicksilver 已提交
149 150
                                    FORMAT_OS_NAME = "${OS_NAME}".replaceAll("\\.", "-")
                                    HELM_RELEASE_NAME = "${env.PIPELINE_NAME}-${env.FROMAT_SEMVER}-${env.BUILD_NUMBER}-single-${FORMAT_OS_NAME}-${BINRARY_VERSION}".toLowerCase()
Q
quicksilver 已提交
151
                                }
152

Q
quicksilver 已提交
153 154
                                agent {
                                    kubernetes {
Q
quicksilver 已提交
155
                                        label "${OS_NAME}-${BINRARY_VERSION}-dev-test"
Q
quicksilver 已提交
156 157 158
                                        defaultContainer 'jnlp'
                                        yamlFile 'ci/jenkins/pod/testEnvironment.yaml'
                                    }
T
add ci  
test 已提交
159 160
                                }

Q
quicksilver 已提交
161
                                stages {
Q
quicksilver 已提交
162
                                    stage('Deploy to Dev') {
Q
quicksilver 已提交
163 164 165 166 167
                                        steps {
                                            container('milvus-test-env') {
                                                script {
                                                    load "${env.WORKSPACE}/ci/jenkins/step/deploySingle2Dev.groovy"
                                                }
168 169 170 171
                                            }
                                        }
                                    }

Q
quicksilver 已提交
172
                                    stage('Dev Test') {
Q
quicksilver 已提交
173 174 175 176 177 178 179 180 181
                                        steps {
                                            container('milvus-test-env') {
                                                script {
                                                    boolean isNightlyTest = isTimeTriggeredBuild()
                                                    if (isNightlyTest) {
                                                        load "${env.WORKSPACE}/ci/jenkins/step/singleDevNightlyTest.groovy"
                                                    } else {
                                                        load "${env.WORKSPACE}/ci/jenkins/step/singleDevTest.groovy"
                                                    }
182 183 184 185
                                                }
                                            }
                                        }
                                    }
Q
quicksilver 已提交
186

Q
quicksilver 已提交
187
                                    stage('Cleanup Dev') {
Q
quicksilver 已提交
188 189 190 191 192
                                        steps {
                                            container('milvus-test-env') {
                                                script {
                                                    load "${env.WORKSPACE}/ci/jenkins/step/cleanupSingleDev.groovy"
                                                }
193 194
                                            }
                                        }
T
add ci  
test 已提交
195 196
                                    }
                                }
Q
quicksilver 已提交
197

Q
quicksilver 已提交
198 199 200 201 202 203
                                post {
                                    unsuccessful {
                                        container('milvus-test-env') {
                                            script {
                                                load "${env.WORKSPACE}/ci/jenkins/step/cleanupSingleDev.groovy"
                                            }
Q
quicksilver 已提交
204 205
                                        }
                                    }
Q
quicksilver 已提交
206 207 208
                                    cleanup {
                                        deleteDir() /* clean up our workspace */
                                    }
Q
quicksilver 已提交
209 210
                                }
                            }
T
add ci  
test 已提交
211 212 213 214 215 216 217 218
                        }
                    }
                }
            }
        }
    }
}

219
boolean isTimeTriggeredBuild() {
220 221
    if (currentBuild.getBuildCauses('hudson.triggers.TimerTrigger$TimerTriggerCause').size() != 0) {
        return true
222 223 224
    }
    return false
}