updateK8sToTargetVersion.Jenkinsfile 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. @Library('jenkins-library-iru@master') _
  2. def Label = "analis-lab-update-${UUID.randomUUID().toString()}"
  3. pipeline {
  4. options {
  5. buildDiscarder logRotator(numToKeepStr: '10')
  6. disableConcurrentBuilds()
  7. timeout(time: 60, unit: 'MINUTES')
  8. }
  9. agent {
  10. kubernetes {
  11. label Label
  12. yaml libraryResource('deployPodDefinition.yaml')
  13. }
  14. }
  15. environment {
  16. CONTEXT='provision@sdsys.office'
  17. DOCKER_IMAGE='web-laboratory/analis'
  18. HELM_GIT_URL='ssh://git@git.sdsys.ru:8022/labportal/k8s.git'
  19. JENKINS_MAIL='jenkins.dev@sdsys.ru'
  20. DOCKER_REGISTRY='images.sdsys.ru'
  21. HELM_REPO='https://images.sdsys.ru/artifactory/helm/'
  22. CHART_NAME=''
  23. CHART_PATH=''
  24. PROJECT=''
  25. HELM_DIR=''
  26. TAG=''
  27. }
  28. parameters {
  29. string(
  30. name: "mailto",
  31. defaultValue: "admin@sdsys.ru",
  32. description: "Email which has to be notified."
  33. )
  34. }
  35. stages {
  36. stage("Prepare to Update") {
  37. steps {
  38. script {
  39. echo "Pull Repo"
  40. gitOps.clone(HELM_GIT_URL)
  41. HELM_DIR = dirOps.calculateDir(HELM_GIT_URL)
  42. CHART_PATH = "helm/" + DOCKER_IMAGE.split("/")[1]
  43. VALUES_FILE = HELM_DIR + "/helm/" + "dev-" + DOCKER_IMAGE.split("/")[1] + ".yaml"
  44. }
  45. }
  46. }
  47. stage("Update Helm Chart values.yaml") {
  48. steps {
  49. script {
  50. echo "View ${VALUES_FILE}"
  51. sh "cat ${VALUES_FILE}"
  52. }
  53. }
  54. }
  55. stage("Update APP") {
  56. steps {
  57. script {
  58. RELEASENAME = DOCKER_IMAGE.split("/")[1]
  59. NAMESPACE = DOCKER_IMAGE.split("/")[1]
  60. try {
  61. echo "Update APP"
  62. k8sHelmOps.upgrade(CONTEXT, NAMESPACE, RELEASENAME, CHART_PATH, VALUES_FILE_PROD, HELM_REPO)
  63. echo "Update success!!!"
  64. }
  65. catch(err) {
  66. echo "Recovering APP"
  67. k8sHelmOps.rollback(CONTEXT, NAMESPACE, RELEASENAME)
  68. throw err
  69. }
  70. }
  71. }
  72. }
  73. // stage("Tagging Image") {
  74. // steps {
  75. // script {
  76. // echo "Tagging ${TAG} to latest"
  77. // IMAGE = "${DOCKER_REGISTRY}/${DOCKER_IMAGE}"
  78. // k8sBuildImage.crane(IMAGE, TAG, 'latest')
  79. // }
  80. // }
  81. // }
  82. }
  83. post {
  84. failure {
  85. mail charset: 'UTF-8',
  86. subject: "Jenkins build ERROR",
  87. mimeType: 'text/html',
  88. to: "${mailto}",
  89. body: "<b>ATTENTION!!!</b> <b><br> Jenkins job failed.\n\n <b><br>Project Name:</b> ${env.JOB_NAME} <b><br>\nBuild Number:</b> ${env.BUILD_NUMBER} <b><br>\nURL Build:</b> ${RUN_DISPLAY_URL}"
  90. }
  91. }
  92. }