NightlyCI.groovy 7.5 KB
Newer Older
1 2
#!/usr/bin/env groovy

3 4
// When scheduling a job that gets automatically triggered by changes,
// you need to include a [cronjob] tag within the commit message.
5
String cron_timezone = "TZ=Asia/Shanghai"
6
String cron_string = BRANCH_NAME == "master" ? "50 22 * * * " : ""
7

8 9
int total_timeout_minutes = 90
int e2e_timeout_seconds = 60 * 60
10

11 12 13
pipeline {
    agent none
    triggers {
14
        cron """${cron_timezone}
15 16 17 18
            ${cron_string}"""
    }
    options {
        timestamps()
19
        timeout(time: total_timeout_minutes, unit: 'MINUTES')
20 21 22 23 24 25 26 27 28 29 30
        buildDiscarder logRotator(artifactDaysToKeepStr: '30')
        // parallelsAlwaysFailFast()
    }
    stages {
        stage ('E2E Test') {
            matrix {
                axes {
                    axis {
                        name 'MILVUS_SERVER_TYPE'
                        values 'standalone', 'distributed'
                    }
31 32 33 34
                    axis {
                        name 'MILVUS_CLIENT'
                        values 'pymilvus', 'pymilvus-orm'
                    }
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
                }
                agent {
                    kubernetes {
                        label "milvus-e2e-test-kind-nightly"
                        inheritFrom 'default'
                        defaultContainer 'main'
                        yamlFile "build/ci/jenkins/pod/krte.yaml"
                        customWorkspace '/home/jenkins/agent/workspace'
                    }
                }
                environment {
                    PROJECT_NAME = "milvus"
                    SEMVER = "${BRANCH_NAME.contains('/') ? BRANCH_NAME.substring(BRANCH_NAME.lastIndexOf('/') + 1) : BRANCH_NAME}"
                    IMAGE_REPO = "dockerhub-mirror-sh.zilliz.cc/milvusdb"
                    DOCKER_BUILDKIT = 1
50
                    ARTIFACTS = "${env.WORKSPACE}/_artifacts"
51 52
                    DOCKER_CREDENTIALS_ID = "f0aacc8e-33f2-458a-ba9e-2c44f431b4d2"
                    TARGET_REPO = "milvusdb"
53 54 55 56 57 58 59
                }
                stages {
                    stage('Test') {
                        steps {
                            container('main') {
                                dir ('tests/scripts') {
                                    script {
60
                                        def clusterEnabled = "false"
61
                                        if ("${MILVUS_SERVER_TYPE}" == "distributed") {
62
                                            clusterEnabled = "true"
63 64
                                        }

65 66 67 68 69
                                        if ("${MILVUS_CLIENT}" == "pymilvus") {
                                            sh """
                                            MILVUS_CLUSTER_ENABLED=${clusterEnabled} \
                                            ./e2e-k8s.sh \
                                            --kind-config "${env.WORKSPACE}/build/config/topology/trustworthy-jwt-ci.yaml" \
70 71
                                            --node-image registry.zilliz.com/kindest/node:v1.20.2 \
                                            --test-timeout ${e2e_timeout_seconds}
72 73 74 75 76 77 78
                                            """
                                        } else if ("${MILVUS_CLIENT}" == "pymilvus-orm") {
                                            sh """
                                            MILVUS_CLUSTER_ENABLED=${clusterEnabled} \
                                            ./e2e-k8s.sh \
                                            --kind-config "${env.WORKSPACE}/build/config/topology/trustworthy-jwt-ci.yaml" \
                                            --node-image registry.zilliz.com/kindest/node:v1.20.2 \
79 80
                                            --test-extra-arg "--tags L0 L1 L2" \
                                            --test-timeout ${e2e_timeout_seconds}
81 82 83 84
                                            """
                                        } else {
                                            error "Error: Unsupported Milvus client: ${MILVUS_CLIENT}"
                                        }
85 86 87 88 89 90 91 92 93 94 95 96
                                    }
                                }
                            }
                        }
                    }
                }
                post {
                    unsuccessful {
                        container('jnlp') {
                            script {
                                emailext subject: '$DEFAULT_SUBJECT',
                                body: '$DEFAULT_CONTENT',
97
                                recipientProviders: [requestor()],
98 99 100 101 102
                                replyTo: '$DEFAULT_REPLYTO',
                                to: 'qa@zilliz.com'
                            }
                        }
                    }
103
                    always {
104 105 106 107
                        container('main') {
                            script {
                                dir("${env.ARTIFACTS}") {
                                    sh "find ./kind -path '*/history/*' -type f | xargs tar -zcvf artifacts-${PROJECT_NAME}-${MILVUS_SERVER_TYPE}-${SEMVER}-${env.BUILD_NUMBER}-e2e-nightly-logs.tar.gz --transform='s:^[^/]*/[^/]*/[^/]*/[^/]*/::g' || true"
108 109 110
                                    if ("${MILVUS_CLIENT}" == "pymilvus-orm") {
                                        sh "tar -zcvf artifacts-${PROJECT_NAME}-${MILVUS_SERVER_TYPE}-${MILVUS_CLIENT}-pytest-logs.tar.gz ./tests/pytest_logs --remove-files || true"
                                    }
111 112
                                    archiveArtifacts artifacts: "**.tar.gz", allowEmptyArchive: true
                                    sh 'docker rm -f \$(docker network inspect -f \'{{ range \$key, \$value := .Containers }}{{ printf "%s " \$key}}{{ end }}\' kind) || true'
113
                                    sh 'docker network rm kind > /dev/null 2>&1 || true'
114 115 116 117 118
                                }
                            }
                        }
                    }
                    success {
119 120
                        container('main') {
                            script {
121 122
                                def date = sh(returnStdout: true, script: 'date +%Y%m%d').trim()
                                def gitShortCommit = sh(returnStdout: true, script: 'git rev-parse --short HEAD').trim()
123

124
                                withCredentials([usernamePassword(credentialsId: "${env.DOCKER_CREDENTIALS_ID}", usernameVariable: 'DOCKER_USERNAME', passwordVariable: 'DOCKER_PASSWORD')]) {
125
                                    sh 'docker login -u ${DOCKER_USERNAME} -p ${DOCKER_PASSWORD}'
126
                                    sh """
127 128 129 130
                                        docker tag localhost:5000/milvus:latest ${TARGET_REPO}/milvus-nightly:${env.BRANCH_NAME}-${date}-${gitShortCommit}
                                        docker tag localhost:5000/milvus:latest ${TARGET_REPO}/milvus-nightly:${env.BRANCH_NAME}-latest
                                        docker push ${TARGET_REPO}/milvus-nightly:${env.BRANCH_NAME}-${date}-${gitShortCommit}
                                        docker push ${TARGET_REPO}/milvus-nightly:${env.BRANCH_NAME}-latest
131
                                    """
132
                                    sh 'docker logout'
133
                                }
134 135 136 137 138 139
                            }
                        }
                    }
                    cleanup {
                        container('main') {
                            script {
140
                                sh 'find . -name . -o -prune -exec rm -rf -- {} +' /* clean up our workspace */
141 142 143 144 145 146 147 148
                            }
                        }
                    }
                }
            }
        }
    }
}