Jenkinsfile-dev 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. PROMO_SDK=[ service_name: 'info_promo-sdk', image: 'iru/promo-sdk', repo: 'git@github.com:icruportal/web-sdk-demo.git', dockerfile: 'Dockerfile-promo-sdk' ]
  2. PROMO_SEO=[ service_name: 'info_promo-seo', image: 'iru/promo-seo', repo: 'git@github.com:icruportal/web-registration.git', dockerfile: 'Dockerfile-promo-seo' ]
  3. pipeline {
  4. agent {
  5. label "swarm"
  6. }
  7. options {
  8. disableConcurrentBuilds()
  9. timeout(time: 20, unit: 'MINUTES')
  10. }
  11. environment {
  12. SERVICE_NAME_SDK='info_promo-sdk'
  13. DOCKER_IMAGE_SDK='iru/promo-sdk'
  14. GIT_REPO_SDK='git@github.com:icruportal/web-sdk-demo.git'
  15. SERVICE_NAME_SEO='info_promo-seo'
  16. DOCKER_IMAGE_SEO='iru/promo-seo'
  17. GIT_REPO_SEO='git@github.com:icruportal/web-registration.git'
  18. DOCKER_FILE_SEO='Dockerfile-promo-seo'
  19. SWARM_GIT_URL='ssh://git@git.sdsys.ru:8022/iru/stack-deploy.git'
  20. SWARM_GIT_NAME='stack-deploy'
  21. JENKINS_MAIL='jenkins@sdsys.ru'
  22. PACKAGE_NAME='web-registry-promo'
  23. DOCKER_CERT_PATH='/run/secrets/swarm'
  24. DHOST='tcp://dev-iru-swarm.infoclinica.lan:2376 DOCKER_TLS_VERIFY=1'
  25. DOCKER_REGISTRY='dev-registry.infoclinica.ru:5000'
  26. NEWTAG=''
  27. }
  28. parameters {
  29. choice (
  30. choices: 'promo-sdk\npromo-seo',
  31. description: 'Which repo to use?',
  32. name: 'GIT_REPO')
  33. string(
  34. name: "branch",
  35. defaultValue: "release",
  36. description: "Which branch to use"
  37. )
  38. string(
  39. name: "mailto",
  40. defaultValue: "admin@sdsys.ru",
  41. description: "Email which has to be notified."
  42. )
  43. }
  44. stages {
  45. stage("Calculate Variables") {
  46. steps {
  47. script {
  48. switch (GIT_REPO) {
  49. case 'promo-sdk':
  50. REPO=PROMO_SDK.repo
  51. DOCKER_IMAGE=PROMO_SDK.image
  52. SERVICE_NAME=PROMO_SDK.service_name
  53. DOCKER_FILE=PROMO_SDK.dockerfile
  54. break
  55. case 'promo-seo':
  56. REPO=PROMO_SEO.repo
  57. DOCKER_IMAGE=PROMO_SEO.image
  58. SERVICE_NAME=PROMO_SEO.service_name
  59. DOCKER_FILE=PROMO_SEO.dockerfile
  60. break
  61. }
  62. echo REPO
  63. echo DOCKER_IMAGE
  64. echo SERVICE_NAME
  65. echo DOCKER_FILE
  66. }
  67. }
  68. }
  69. // stage("Build") {
  70. // steps {
  71. // script {
  72. // echo "Building ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${BUILD_NUMBER}."
  73. // withCredentials([sshUserPrivateKey(credentialsId: 'provision', keyFileVariable: 'GIT_SSH_KEY', passphraseVariable: '', usernameVariable: 'GIT_SSH_USERNAME')]) {
  74. // sh """set +x
  75. // cat ${GIT_SSH_KEY} > ${WORKSPACE}/id_rsa
  76. // chmod 600 ${WORKSPACE}/id_rsa
  77. // """
  78. // }
  79. // sh "docker build --build-arg branch=${branch} --build-arg git_repo=${REPO} --no-cache -t ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${BUILD_NUMBER} -f ./${DOCKER_FILE} ."
  80. // NEWTAG = sh(script: "docker run --rm ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${BUILD_NUMBER} cat /tmp/version 2> /dev/null", returnStdout: true).trim()
  81. // NEWTAG = branch + "-" + NEWTAG + "_" + BUILD_NUMBER
  82. // echo "NEWTAG is $NEWTAG"
  83. // sh "docker tag ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${BUILD_NUMBER} ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${NEWTAG}"
  84. // }
  85. // }
  86. // }
  87. // stage("Publish") {
  88. // steps {
  89. // echo "Publishing ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${NEWTAG}"
  90. // sh "docker push ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${NEWTAG}"
  91. // }
  92. // }
  93. // stage("Update") {
  94. // steps {
  95. // script {
  96. // try{
  97. // sh "DOCKER_HOST=${DHOST} docker service update ${SERVICE_NAME} --image ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${NEWTAG}"
  98. // }
  99. // catch(err){
  100. // echo "Recovering service $item"
  101. // sh "DOCKER_HOST=${DHOST} docker service rollback ${SERVICE_NAME}"
  102. // throw err
  103. // }
  104. // }
  105. // }
  106. // }
  107. // stage("Tagging"){
  108. // steps{
  109. // echo "Setting latest tag"
  110. // sh """docker tag ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${NEWTAG} ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:latest
  111. // docker push ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:latest"""
  112. // echo "Updating tag info in ${SWARM_GIT_NAME} repository"
  113. // withCredentials([sshUserPrivateKey(credentialsId: 'provision', keyFileVariable: 'GIT_SSH_KEY', passphraseVariable: '', usernameVariable: 'GIT_SSH_USERNAME')]) {
  114. // sh """GIT_SSH_COMMAND='ssh -i ${GIT_SSH_KEY} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' \
  115. // git clone ${SWARM_GIT_URL}
  116. // cd ${SWARM_GIT_NAME}
  117. // echo -n ${NEWTAG} > tags/${DOCKER_IMAGE}.dev-version
  118. // git add -A
  119. // git config --global user.email "${JENKINS_MAIL}"
  120. // git config --global user.name "Jenkins"
  121. // git commit -m 'Version update'
  122. // GIT_SSH_COMMAND='ssh -i ${GIT_SSH_KEY} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' \
  123. // git push origin master
  124. // """
  125. // }
  126. // }
  127. // }
  128. }
  129. post {
  130. always {
  131. echo "CleaningUp work diretory"
  132. deleteDir()
  133. sh "docker image rm -f `docker image ls -q ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${BUILD_NUMBER}`"
  134. }
  135. failure {
  136. mail charset: 'UTF-8',
  137. subject: "Jenkins build ERROR",
  138. mimeType: 'text/html',
  139. to: "${mailto}",
  140. 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}"
  141. }
  142. }
  143. }