Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env groovy
- @Library('glib') _
- def branch = env.branch
- def image = 'website-middle'
- def imageTag = env.BUILD_TAG
- def repo_url = 'https://git.cashwagon.com/pdl/website_middle'
- def country = env.country
- def helm_name = 'testing-middle'
- def k8s_cluster = 'arn:aws:eks:ap-southeast-1:843334049208:cluster/cw-eks-cluster-test'
- properties([
- gitLabConnection('https://git.cashwagon.com'),
- disableConcurrentBuilds(),
- parameters([
- choice(
- name: 'country',
- choices: ['vn', 'lk', 'ph', "id"],
- description: 'Choose country' ),
- gitParameter(branch: '',
- branchFilter: 'origin/(.*)',
- defaultValue: 'develop',
- description: '',
- name: 'branch',
- quickFilterEnabled: true,
- selectedValue: 'DEFAULT',
- sortMode: 'DESCENDING_SMART',
- tagFilter: '*',
- useRepository: repo_url,
- listSize: '10',
- type: 'PT_BRANCH_TAG')
- ])
- ])
- currentBuild.description = "Deploy and test site: ${country} (branch: ${branch})"
- try {
- slackNotifierStart(branch, env.gitlabUserName)
- node('gitlab') {
- stage("Build ${image} docker image") {
- git branch: branch, credentialsId: '75b6d7cb-3de1-4ea1-9c47-f02129759b19', url: repo_url
- withDockerRegistry(credentialsId: 'harbor-registry', url: 'https://harbor.cashwagon.com') {
- def app = docker.build("harbor.cashwagon.com/ci-images/${image}", '.')
- app.push("${imageTag}")
- }
- }
- stage("DB migrate") {
- withCredentials([
- string(credentialsId: 'CONSUL_TOKEN', variable: 'CONSUL_TOKEN'),
- string(credentialsId: 'CONSUL_AUTH', variable: 'CONSUL_AUTH')
- ]){
- withDockerRegistry(credentialsId: 'harbor-registry', url: 'https://harbor.cashwagon.com') {
- sh "docker run --rm -e CONSUL_ADDR=https://consul.cashwagon.com -e ENV=k8s" +
- " -e APPLICATION=website_middle_${country} -e CONSUL_TOKEN=${CONSUL_TOKEN} " +
- " -e CONSUL_AUTH=${CONSUL_AUTH} harbor.cashwagon.com/ci-images/${image}:${imageTag} " +
- "'bundle exec rake db:migrate' "
- }
- }
- }
- stage("DB seed") {
- withCredentials([
- string(credentialsId: 'CONSUL_TOKEN', variable: 'CONSUL_TOKEN'),
- string(credentialsId: 'CONSUL_AUTH', variable: 'CONSUL_AUTH')
- ]){
- withDockerRegistry(credentialsId: 'harbor-registry', url: 'https://harbor.cashwagon.com') {
- sh "docker run --rm -e CONSUL_ADDR=https://consul.cashwagon.com -e ENV=k8s" +
- " -e APPLICATION=website_middle_${country} -e CONSUL_TOKEN=${CONSUL_TOKEN} " +
- " -e CONSUL_AUTH=${CONSUL_AUTH} harbor.cashwagon.com/ci-images/${image}:${imageTag} " +
- "'bundle exec rake db:seed' "
- }
- }
- }
- }
- node('master') {
- stage("Deploy helm release ${helm_name}") {
- git branch: branch, credentialsId: '75b6d7cb-3de1-4ea1-9c47-f02129759b19', url: repo_url
- sh "kubectl config use-context ${k8s_cluster}"
- sh "helm upgrade -i ${helm_name} ./charts -f ./charts/values-stage-${country}.yaml " +
- "--set imageTag=${env.BUILD_TAG},CONSUL_APPLICATION=website_middle_${country} " +
- "--kube-context ${k8s_cluster} --wait"
- }
- }
- } catch (e) {
- currentBuild.result = 'FAILURE'
- throw e
- } finally {
- def currentResult = currentBuild.result ?: 'SUCCESS'
- slackNotifier(currentResult)
- }
- // Auto-testing
- try {
- node('qa-worker') {
- sleep 30
- stage('auto-testing') {
- parallel (
- "createAppViaAPI" : {
- build job: 'qa_site_api_create_app', parameters: [string(name: 'country', value: country)]
- }
- )
- }
- }
- } catch (e) {
- currentBuild.result = "UNSTABLE"
- slackSend color: "danger", channel: "#site_deploy_at", message: "Auto-testing after deployment failed on *stage [${country}]* (<https://jenkins.cashwagon.com/blue/organizations/jenkins/website_middle_stage_k8s/detail/website_middle_stage_k8s/${env.BUILD_NUMBER}/pipeline|${env.JOB_NAME} - build #${env.BUILD_NUMBER}>)! :x:"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement