buildImage.Jenkinsfile 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. SVN_DIR='analis'
  22. REV_NUMBER=''
  23. PROJECT=''
  24. CHART_NAME=''
  25. CHART_PATH=''
  26. HELM_DIR=''
  27. TAG=''
  28. }
  29. parameters {
  30. string(
  31. name: "REVNUM",
  32. defaultValue: "HEAD",
  33. description: "Revision number"
  34. )
  35. string(
  36. name: "mailto",
  37. defaultValue: "admin@sdsys.ru",
  38. description: "Email which has to be notified."
  39. )
  40. }
  41. stages {
  42. stage("SVN Checkout") {
  43. steps {
  44. script {
  45. svnOps.checkout(REPO, SVN_DIR, REVNUM)
  46. REV_NUMBER = svnOps.revNumber(SVN_DIR)
  47. sh "echo 'REV_NUMBER = ${REV_NUMBER}'"
  48. PROJECT = DOCKER_IMAGE.split("/")[1]
  49. }
  50. }
  51. }
  52. stage("Build Image") {
  53. steps {
  54. script {
  55. echo "Build Image with Kaniko"
  56. REGISTRY = "${DOCKER_REGISTRY}/${DOCKER_IMAGE}"
  57. TAG = "${REV_NUMBER}-${BUILD_NUMBER}"
  58. k8sBuildImage.kaniko(REGISTRY, TAG)
  59. }
  60. }
  61. }
  62. stage("Update Helm Chart values.yaml") {
  63. steps {
  64. script {
  65. echo "Update Helm Chart"
  66. def data = readYaml file: "${CHART_PATH}/values.yaml"
  67. TAG_PATH = "images.${PROJECT}.build"
  68. yamlOps.updateBuilder(TAG_PATH, data, TAG)
  69. writeYaml file: "${CHART_PATH}/values.yaml", data: data, overwrite: true
  70. }
  71. }
  72. }
  73. stage("Push changes to REPO") {
  74. steps {
  75. script {
  76. echo "Push changes to Repo"
  77. COMMIT = "Version update ${PROJECT}"
  78. gitOps.push(HELM_DIR, COMMIT)
  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. }