buildImage.Jenkinsfile 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. @Library('jenkins-library@master') _
  2. def Label = "analis-lab-build-${UUID.randomUUID().toString()}"
  3. pipeline {
  4. options {
  5. buildDiscarder logRotator(numToKeepStr: '10')
  6. disableConcurrentBuilds()
  7. timeout(time: 15, unit: 'MINUTES')
  8. }
  9. agent {
  10. kubernetes {
  11. label Label
  12. yaml libraryResource('analisBuildPodDefinition.yaml')
  13. }
  14. }
  15. environment {
  16. CLOUD='cloud-it-k8s'
  17. JENKINS_MAIL='jenkins.dev@sdsys.ru'
  18. DOCKER_REGISTRY='jcr.infoclinica.ru'
  19. DOCKER_IMAGE='lab/analis'
  20. REPO='svn://192.168.21.250/programs/trunk/Services/Analis/Win32'
  21. HELM_GIT_URL='ssh://git@git.sdsys.ru:8022/labportal/k8s.git'
  22. CHART_SUBPATH='helm/analis'
  23. SVN_DIR='analis'
  24. REV_NUMBER=''
  25. PROJECT=''
  26. CHART_PATH=''
  27. HELM_DIR=''
  28. TAG=''
  29. }
  30. parameters {
  31. string(
  32. name: "REVNUM",
  33. defaultValue: "HEAD",
  34. description: "Revision number"
  35. )
  36. string(
  37. name: "mailto",
  38. defaultValue: "admin@sdsys.ru",
  39. description: "Email which has to be notified."
  40. )
  41. }
  42. stages {
  43. stage("SVN Checkout") {
  44. steps {
  45. script {
  46. svnOps.checkout(REPO, SVN_DIR, REVNUM)
  47. REV_NUMBER = svnOps.revNumber(SVN_DIR)
  48. sh "echo 'REV_NUMBER = ${REV_NUMBER}'"
  49. gitOps.clone(HELM_GIT_URL)
  50. HELM_DIR = dirOps.calculateDir(HELM_GIT_URL)
  51. PROJECT = DOCKER_IMAGE.split("/")[1]
  52. CHART_PATH = "${HELM_DIR}/${CHART_SUBPATH}"
  53. }
  54. }
  55. }
  56. stage("Build Image") {
  57. steps {
  58. script {
  59. echo "Build Image with Kaniko"
  60. REGISTRY = "${DOCKER_REGISTRY}/${DOCKER_IMAGE}"
  61. TAG = "${REV_NUMBER}-${BUILD_NUMBER}"
  62. k8sBuildImage.kaniko(REGISTRY, TAG)
  63. }
  64. }
  65. }
  66. stage("Update Helm Chart values.yaml") {
  67. steps {
  68. script {
  69. echo "Update Helm Chart"
  70. def data = readYaml file: "${CHART_PATH}/values.yaml"
  71. TAG_PATH = "images.${PROJECT}.build"
  72. yamlOps.updateBuilder(TAG_PATH, data, TAG)
  73. writeYaml file: "${CHART_PATH}/values.yaml", data: data, overwrite: true
  74. }
  75. }
  76. }
  77. stage("Push changes to REPO") {
  78. steps {
  79. script {
  80. echo "Push changes to Repo"
  81. COMMIT = "Version update ${PROJECT}"
  82. gitOps.push(HELM_DIR, COMMIT)
  83. }
  84. }
  85. }
  86. }
  87. post {
  88. failure {
  89. mail charset: 'UTF-8',
  90. subject: "Jenkins build ERROR",
  91. mimeType: 'text/html',
  92. to: "${mailto}",
  93. 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}"
  94. }
  95. }
  96. }