k8-test.jenkinsfile 3.71 KB
Newer Older
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 38 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 64 65 66 67 68 69
pipeline {
    agent any
    environment {
        SLACK = credentials('slack-notification')
    }
    parameters {
        choice(
            name: 'EBI_SEARCH_ENDPOINT',
            choices: ['DEV', 'PRO'],
            description: 'Which ebi search index to use?'
        )
        choice(
            name: 'DATABASE',
            choices: ['PRO', 'DEV', 'TEST', 'HH', 'FB'],
            description: 'Which database instance to use?'
        )
        gitParameter(
            branchFilter: 'origin/(.*)',
            defaultValue: 'master',
            name: 'BRANCH',
            type: 'PT_BRANCH',
            description: 'Name of the branch to test and deploy'
        )
    }
    stages {
        stage("deploy") {
            steps {
                script {
                    // set DB with the corresponding Secret file (from K8)
                    switch(params.DATABASE) {
                        case 'PRO':
                            env.DB = 'db-pro'
                            break
                        case 'DEV':
                            env.DB = 'db-dev'
                            break
                        case 'TEST':
                            env.DB = 'db-test'
                            break
                        case 'FB':
                            env.DB = 'db-fb'
                            break
                        case 'HH':
                            env.DB = 'db-hh'
                            break
                    }

                    // set SEARCH_INDEX
                    switch(params.EBI_SEARCH_ENDPOINT) {
                        case 'PRO':
                            env.SEARCH_INDEX = 'search-index-prod'
                            break
                        case 'DEV':
                            env.SEARCH_INDEX = 'search-index-dev'
                            break
                    }

                    withCredentials([file(credentialsId: 'HX-WP-Config', variable: 'config')]) {
                        sh """
                            # update repository
                            git reset --hard
                            git fetch --all
                            git checkout ${params.BRANCH}
                            git pull

                            # send start message on Slack
                            curl -X POST -H 'Content-type: application/json' --data '{"text":"Starting deployment of ${params.BRANCH} in the development namespace - HX cluster"}' $SLACK

                            # clear the cache
carlosribas's avatar
carlosribas committed
70 71
                            POD=`/net/isilonP/public/rw/homes/xfm_adm/.jenkins/kubectl --kubeconfig=${config} get pod -l app=memcached -o jsonpath="{.items[0].metadata.name}"`
                            /net/isilonP/public/rw/homes/xfm_adm/.jenkins/kubectl --kubeconfig=${config} exec -it \$POD -- sh -c "echo flush_all | nc localhost 11211"
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88

                            # reinstall everything
                            cd kubernetes/helm
                            /net/isilonP/public/rw/homes/xfm_adm/.jenkins/helm uninstall full-dev --kubeconfig ${config} --namespace dev
                            sleep 10
                            /net/isilonP/public/rw/homes/xfm_adm/.jenkins/helm upgrade --install full-dev --kubeconfig ${config} --namespace dev --set proxy=proxy-hx,database=${DB},searchIndex=${SEARCH_INDEX},rnacentralBranch=${params.BRANCH} .
                            sleep 10

                            # send final message on Slack
                            curl -X POST -H 'Content-type: application/json' --data '{"text":"Deployed ${params.BRANCH} in the development namespace - HX cluster. This may take a few more seconds."}' $SLACK
                        """
                    }
                }
            }
        }
    }
}