devK8s.Jenkinsfile 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. @Library('jenkins-library@master') _
  2. def Label = "promo-build-${UUID.randomUUID().toString()}"
  3. pipeline {
  4. options {
  5. buildDiscarder logRotator(numToKeepStr: '10')
  6. disableConcurrentBuilds()
  7. }
  8. agent {
  9. kubernetes {
  10. label Label
  11. yaml libraryResource('promoPodDefinition.yaml')
  12. }
  13. }
  14. environment {
  15. CLOUD='cloud-it-k8s'
  16. DOCKER_IMAGE='iru/promo'
  17. CHART_PATH='helm/info'
  18. NAMESPACE='info'
  19. HELM_GIT_URL='ssh://git@git.sdsys.ru:8022/iru/k8s.git'
  20. APP_GIT_URL='ssh://gitolite@git.alfatell.ru:2223/web-registration-cloud.git'
  21. JENKINS_MAIL='jenkins.dev@sdsys.ru'
  22. DOCKER_REGISTRY='jcr.infoclinica.ru'
  23. CHART_NAME=''
  24. APP_DIR=''
  25. HELM_DIR=''
  26. TAG=''
  27. }
  28. parameters {
  29. string(
  30. name: "branch",
  31. defaultValue: "release",
  32. description: "Which branch to use"
  33. )
  34. string(
  35. name: "mailto",
  36. defaultValue: "admin@sdsys.ru",
  37. description: "Email which has to be notified."
  38. )
  39. }
  40. stages {
  41. stage("Prepare to build") {
  42. steps {
  43. script {
  44. echo "Pull ${APP_GIT_URL}"
  45. gitOps.clone(APP_GIT_URL)
  46. APP_DIR = dirOps.calculateDir(APP_GIT_URL)
  47. echo "CheckOut ${branch}"
  48. gitOps.checkout(APP_DIR, branch)
  49. echo "Save Version"
  50. dir(APP_DIR) {
  51. sh 'echo $(git log -p -1 --pretty=format:"%h"|head -n1) > version'
  52. }
  53. }
  54. }
  55. }
  56. stage("Build APP") {
  57. steps {
  58. script {
  59. echo "Build customer-api"
  60. dir("${APP_DIR}/customer-api") {
  61. buildOps.maven()
  62. }
  63. echo "Build Promo"
  64. dir("${APP_DIR}/promo") {
  65. buildOps.gradle()
  66. }
  67. }
  68. }
  69. }
  70. stage("Build Image") {
  71. steps {
  72. script {
  73. sh "cp ${APP_DIR}/promo/build/libs/promo-0.0.1-SNAPSHOT.war ."
  74. sh "cp ${APP_DIR}/version ."
  75. REGISTRY = DOCKER_REGISTRY + "/" + DOCKER_IMAGE
  76. COMMIT = sh(script: "cat version 2> /dev/null", returnStdout: true).trim()
  77. TAG = "${COMMIT}-${BUILD_NUMBER}"
  78. echo "Build Image with Kaniko with parameters"
  79. echo "Repository: ${REGISTRY}"
  80. echo "Tag: ${TAG}"
  81. k8sBuildImage.kaniko(REGISTRY, TAG)
  82. }
  83. }
  84. }
  85. }
  86. }