Commit 90d1c2ac authored by carlosribas's avatar carlosribas
Browse files

New K8 pipeline

parent 494d6073
pipeline {
agent any
environment {
SLACK = credentials('slack-notification')
}
parameters {
choice(
name: 'EBI_SEARCH_ENDPOINT',
choices: ['PRO', 'DEV'],
description: 'Which ebi search index to use?'
)
choice(
name: 'DATABASE',
choices: ['HH', 'PRO', 'DEV', 'TEST', '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: 'HH-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 production namespace - HH cluster"}' $SLACK
# clear the cache
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"
# reinstall everything
cd kubernetes/helm
/net/isilonP/public/rw/homes/xfm_adm/.jenkins/helm uninstall full-prod --kubeconfig ${config} --namespace prod
sleep 10
/net/isilonP/public/rw/homes/xfm_adm/.jenkins/helm upgrade --install full-prod --kubeconfig ${config} --namespace prod --set proxy=proxy-hh,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 production namespace - HH cluster. This may take a few more seconds."}' $SLACK
"""
}
}
}
}
}
}
pipeline {
agent any
environment {
SLACK = credentials('slack-notification')
}
parameters {
choice(
name: 'EBI_SEARCH_ENDPOINT',
choices: ['PRO', 'DEV'],
description: 'Which ebi search index to use?'
)
choice(
name: 'DATABASE',
choices: ['FB', 'PRO', 'DEV', 'TEST', '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 {
// 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 production namespace - HX cluster"}' $SLACK
# clear the cache
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"
# reinstall everything
cd kubernetes/helm
/net/isilonP/public/rw/homes/xfm_adm/.jenkins/helm uninstall full-prod --kubeconfig ${config} --namespace prod
sleep 10
/net/isilonP/public/rw/homes/xfm_adm/.jenkins/helm upgrade --install full-prod --kubeconfig ${config} --namespace prod --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 production namespace - HX cluster. This may take a few more seconds."}' $SLACK
"""
}
}
}
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment