wp-kubernetes.jenkinsfile 6.9 KB
Newer Older
carlosribas's avatar
carlosribas committed
1 2
pipeline {
    agent any
carlosribas's avatar
carlosribas committed
3 4 5
    environment {
        SLACK = credentials('slack-notification')
    }
carlosribas's avatar
carlosribas committed
6 7 8
    parameters {
        choice(
            name: 'WEB',
carlosribas's avatar
carlosribas committed
9
            choices: ['TEST', 'PROD-HX', 'PROD-HH'],
carlosribas's avatar
carlosribas committed
10 11
            description: 'Which website do you want to update?'
        )
12 13 14 15 16
        choice(
            name: 'EBI_SEARCH_ENDPOINT',
            choices: ['PRO', 'DEV'],
            description: 'Which ebi search index to use?'
        )
carlosribas's avatar
carlosribas committed
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
        choice(
            name: 'DATABASE',
            choices: ['PRO', 'DEV', 'TEST', 'FB', 'HH'],
            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 {
carlosribas's avatar
carlosribas committed
34
                    // set DB with the corresponding Secret file (from K8)
carlosribas's avatar
carlosribas committed
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
                    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
                    }

carlosribas's avatar
carlosribas committed
53
                    // set parameters
carlosribas's avatar
carlosribas committed
54 55 56 57
                    switch(params.WEB) {
                        case 'TEST':
                            env.RELEASE = 'full-dev'
                            env.NAMESPACE = 'dev'
carlosribas's avatar
carlosribas committed
58
                            env.VALUES = '--values=values.dev.yaml'
carlosribas's avatar
carlosribas committed
59 60 61 62 63 64 65
                            env.CLUSTER = 'HX'
                            break
                        case 'PROD-HX':
                            env.RELEASE = 'full-prod'
                            env.NAMESPACE = 'prod'
                            env.VALUES = ''
                            env.CLUSTER = 'HX'
carlosribas's avatar
carlosribas committed
66
                            break
carlosribas's avatar
carlosribas committed
67
                        case 'PROD-HH':
carlosribas's avatar
carlosribas committed
68 69
                            env.RELEASE = 'full-prod'
                            env.NAMESPACE = 'prod'
carlosribas's avatar
carlosribas committed
70
                            env.VALUES = ''
carlosribas's avatar
carlosribas committed
71
                            env.CLUSTER = 'HH'
carlosribas's avatar
carlosribas committed
72 73 74
                            break
                    }

75 76 77 78 79 80 81 82 83 84
                    // 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
                    }

carlosribas's avatar
carlosribas committed
85
                    if ("${CLUSTER}" == "HX") {
86
                        withCredentials([file(credentialsId: 'HX-WP-Config', variable: 'config-hx')]) {
carlosribas's avatar
carlosribas committed
87
                            sh """
carlosribas's avatar
carlosribas committed
88 89 90 91 92 93 94
                                # update repository
                                git reset --hard
                                git fetch --all
                                git checkout ${params.BRANCH}
                                git pull

                                # send start message on Slack
carlosribas's avatar
carlosribas committed
95
                                curl -X POST -H 'Content-type: application/json' --data '{"text":"Starting deployment of ${params.BRANCH} in ${params.WEB}"}' $SLACK
carlosribas's avatar
carlosribas committed
96 97

                                # clear the cache
98 99
                                POD=`/net/isilonP/public/rw/homes/xfm_adm/.jenkins/kubectl --kubeconfig=${config-hx} get pod -l app=memcached -o jsonpath="{.items[0].metadata.name}"`
                                /net/isilonP/public/rw/homes/xfm_adm/.jenkins/kubectl --kubeconfig=${config-hx} exec -it \$POD -- sh -c "echo flush_all | nc localhost 11211"
carlosribas's avatar
carlosribas committed
100 101

                                # reinstall everything
carlosribas's avatar
carlosribas committed
102
                                cd kubernetes/helm
103
                                /net/isilonP/public/rw/homes/xfm_adm/.jenkins/helm uninstall ${RELEASE} --kubeconfig ${config-hx} --namespace ${NAMESPACE}
carlosribas's avatar
carlosribas committed
104
                                sleep 10
105
                                /net/isilonP/public/rw/homes/xfm_adm/.jenkins/helm upgrade --install ${RELEASE} --kubeconfig ${config-hx} --namespace ${NAMESPACE} ${VALUES} --set proxy=proxy-hx,database=${DB},searchIndex=${SEARCH_INDEX},rnacentralBranch=${params.BRANCH} .
carlosribas's avatar
carlosribas committed
106 107 108
                                sleep 10

                                # send final message on Slack
carlosribas's avatar
carlosribas committed
109
                                curl -X POST -H 'Content-type: application/json' --data '{"text":"Deployed ${params.BRANCH} in ${params.WEB}. This may take a few more seconds."}' $SLACK
carlosribas's avatar
carlosribas committed
110 111
                            """
                        }
carlosribas's avatar
carlosribas committed
112
                    } else if ("${CLUSTER}" == "HH") {
113
                        withCredentials([file(credentialsId: 'HH-WP-Config', variable: 'config-hh')]) {
carlosribas's avatar
carlosribas committed
114
                            sh """
carlosribas's avatar
carlosribas committed
115 116 117 118 119 120 121
                                # update repository
                                git reset --hard
                                git fetch --all
                                git checkout ${params.BRANCH}
                                git pull

                                # send start message on Slack
carlosribas's avatar
carlosribas committed
122
                                curl -X POST -H 'Content-type: application/json' --data '{"text":"Starting deployment of ${params.BRANCH} in ${params.WEB}"}' $SLACK
carlosribas's avatar
carlosribas committed
123 124

                                # clear the cache
125 126
                                POD=`/net/isilonP/public/rw/homes/xfm_adm/.jenkins/kubectl --kubeconfig=${config-hh} get pod -l app=memcached -o jsonpath="{.items[0].metadata.name}"`
                                /net/isilonP/public/rw/homes/xfm_adm/.jenkins/kubectl --kubeconfig=${config-hh} exec -it \$POD -- sh -c "echo flush_all | nc localhost 11211"
carlosribas's avatar
carlosribas committed
127 128

                                # reinstall everything
carlosribas's avatar
carlosribas committed
129
                                cd kubernetes/helm
130
                                /net/isilonP/public/rw/homes/xfm_adm/.jenkins/helm uninstall ${RELEASE} --kubeconfig ${config-hh} --namespace ${NAMESPACE}
carlosribas's avatar
carlosribas committed
131
                                sleep 10
132
                                /net/isilonP/public/rw/homes/xfm_adm/.jenkins/helm upgrade --install ${RELEASE} --kubeconfig ${config-hh} --namespace ${NAMESPACE} ${VALUES} --set proxy=proxy-hh,database=${DB},searchIndex=${SEARCH_INDEX},rnacentralBranch=${params.BRANCH} .
carlosribas's avatar
carlosribas committed
133 134 135
                                sleep 10

                                # send final message on Slack
carlosribas's avatar
carlosribas committed
136
                                curl -X POST -H 'Content-type: application/json' --data '{"text":"Deployed ${params.BRANCH} in ${params.WEB}. This may take a few more seconds."}' $SLACK
carlosribas's avatar
carlosribas committed
137 138 139 140 141 142 143
                            """
                        }
                    }
                }
            }
        }
    }
carlosribas's avatar
carlosribas committed
144
}