buildImage.Jenkinsfile 2.5 KB

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