Jenkinsfile 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. pipeline {
  2. agent {
  3. label "swarm"
  4. }
  5. options {
  6. disableConcurrentBuilds()
  7. timeout(time: 20, unit: 'MINUTES')
  8. }
  9. environment {
  10. DOCKER_IMAGE='lab/analis-wineservice'
  11. DOCKER_REGISTRY='registry.infoclinica.ru:5000'
  12. SWARM_GIT_URL='ssh://git@git.sdsys.ru:8022/labportal/stack-deploy.git'
  13. SWARM_GIT_NAME='stack-deploy'
  14. JENKINS_MAIL='jenkins@sdsys.ru'
  15. NEWTAG=''
  16. REV_NUMBER=''
  17. }
  18. parameters {
  19. string(
  20. name: "mailto",
  21. defaultValue: "admin@sdsys.ru",
  22. description: "Email which has to be notified."
  23. )
  24. }
  25. stages {
  26. stage("SVN Checkout") {
  27. steps {
  28. sh """[ -d analis/.svn ] && svn cleanup analis
  29. svn co --force --no-auth-cache svn://192.168.21.250/programs/trunk/Services/Analis/Win32 analis --username public --password "sds#7753435"
  30. """
  31. }
  32. }
  33. stage("Build") {
  34. steps {
  35. script {
  36. // Discover revision number
  37. REV_NUMBER=sh (script: "svn info --show-item last-changed-revision analis", returnStdout: true ).trim()
  38. echo "Last-Changed-Revision number is '$REV_NUMBER'"
  39. }
  40. sh "docker build -t ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${REV_NUMBER}-${BUILD_NUMBER} ."
  41. sh "docker tag ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${REV_NUMBER}-${BUILD_NUMBER} ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:latest"
  42. }
  43. }
  44. stage("Publish") {
  45. steps {
  46. sh "docker push ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${REV_NUMBER}-${BUILD_NUMBER}"
  47. sh "docker push ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:latest"
  48. }
  49. }
  50. stage("Tagging"){
  51. steps{
  52. withCredentials([sshUserPrivateKey(credentialsId: 'provision', keyFileVariable: 'GIT_SSH_KEY', passphraseVariable: '', usernameVariable: 'GIT_SSH_USERNAME')]) {
  53. sh """[ -d ${SWARM_GIT_NAME} ] && rm -rf ${SWARM_GIT_NAME}
  54. GIT_SSH_COMMAND='ssh -i ${GIT_SSH_KEY} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' \
  55. git clone ${SWARM_GIT_URL}
  56. cd ${SWARM_GIT_NAME}
  57. echo -n ${REV_NUMBER}-${BUILD_NUMBER} > tags/${DOCKER_IMAGE}.build-version
  58. git add -A
  59. git config --global user.email "${JENKINS_MAIL}"
  60. git config --global user.name "Jenkins"
  61. git commit -m "Version update tags/lab/${DOCKER_IMAGE}.build-version = ${REV_NUMBER}-${BUILD_NUMBER}"
  62. GIT_SSH_COMMAND='ssh -i ${GIT_SSH_KEY} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' \
  63. git push origin master
  64. cd ..
  65. rm -rf ${SWARM_GIT_NAME}
  66. ls"""
  67. }
  68. }
  69. }
  70. }
  71. post {
  72. failure {
  73. mail charset: 'UTF-8',
  74. subject: "Jenkins build ERROR",
  75. mimeType: 'text/html',
  76. to: "${mailto}",
  77. body: "<b>ATTENTION!!!</b> Jenkins job <b>FAILED.</b>\n\n <br>Project Name: ${env.JOB_NAME}\n <br>Build TAG: <b>${REV_NUMBER}-${BUILD_NUMBER}</b>\n <br>Build URL: ${RUN_DISPLAY_URL}"
  78. }
  79. success {
  80. mail charset: 'UTF-8',
  81. subject: "Jenkins build SUSCCESS",
  82. mimeType: 'text/html',
  83. to: "${mailto}",
  84. body: "<b>Congradulations!!!</b> Jenkins job successfully finished\n\n <br>Project Name: ${env.JOB_NAME}\n <br>Build TAG: <b>${REV_NUMBER}-${BUILD_NUMBER}</b>\n <br>Build URL: ${RUN_DISPLAY_URL}"
  85. }
  86. }
  87. }