buildImage.Jenkinsfile 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. @Library('jenkins-library@master') _
  2. def Label = "analis-iru-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. PROJECT = DOCKER_IMAGE.split("/")[1]
  50. HELM_DIR = dirOps.calculateDir(HELM_GIT_URL)
  51. CHART_PATH = "${HELM_DIR}/${CHART_SUBPATH}"
  52. }
  53. }
  54. }
  55. stage("Build Image") {
  56. steps {
  57. script {
  58. echo "Build Image with Kaniko"
  59. REGISTRY = "${DOCKER_REGISTRY}/${DOCKER_IMAGE}"
  60. TAG = "${REV_NUMBER}-${BUILD_NUMBER}"
  61. k8sBuildImage.kaniko(REGISTRY, TAG)
  62. }
  63. }
  64. }
  65. stage("Update Helm Chart values.yaml") {
  66. steps {
  67. script {
  68. echo "Update Helm Chart"
  69. def data = readYaml file: "${CHART_PATH}/values.yaml"
  70. TAG_PATH = "images.${PROJECT}.build"
  71. yamlOps.updateBuilder(TAG_PATH, data, TAG)
  72. writeYaml file: "${CHART_PATH}/values.yaml", data: data, overwrite: true
  73. }
  74. }
  75. }
  76. stage("Push changes to REPO") {
  77. steps {
  78. script {
  79. echo "Push changes to Repo"
  80. COMMIT = "Version update ${PROJECT}"
  81. gitOps.push(HELM_DIR, COMMIT)
  82. }
  83. }
  84. }
  85. }
  86. post {
  87. failure {
  88. mail charset: 'UTF-8',
  89. subject: "Jenkins build ERROR",
  90. mimeType: 'text/html',
  91. to: "${mailto}",
  92. 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}"
  93. }
  94. }
  95. }