Jenkinsfile 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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='dev-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. DHOST='tcp://dev-iru-swarm.infoclinica.lan:2376 DOCKER_TLS_VERIFY=1'
  16. NEWTAG=''
  17. REV_NUMBER=''
  18. }
  19. parameters {
  20. string(
  21. name: "mailto",
  22. defaultValue: "admin@sdsys.ru",
  23. description: "Email which has to be notified."
  24. )
  25. }
  26. stages {
  27. stage("SVN Checkout") {
  28. steps {
  29. sh """[ -d analis/.svn ] && svn cleanup analis
  30. svn co --force --no-auth-cache svn://192.168.21.250/programs/trunk/Services/Analis/Win64 analis --username public --password "sds#7753435"
  31. """
  32. }
  33. }
  34. stage("Build") {
  35. steps {
  36. script {
  37. // Discover revision number
  38. REV_NUMBER=sh (script: "svn info --show-item last-changed-revision analis", returnStdout: true ).trim()
  39. echo "Last-Changed-Revision number is '$REV_NUMBER'"
  40. }
  41. sh "docker build -t ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${REV_NUMBER}-${BUILD_NUMBER} ."
  42. sh "docker tag ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${REV_NUMBER}-${BUILD_NUMBER} ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:latest"
  43. }
  44. }
  45. stage("Publish") {
  46. steps {
  47. sh "docker push ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${REV_NUMBER}-${BUILD_NUMBER}"
  48. sh "docker push ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:latest"
  49. }
  50. }
  51. stage("Tagging"){
  52. steps{
  53. withCredentials([sshUserPrivateKey(credentialsId: 'provision', keyFileVariable: 'GIT_SSH_KEY', passphraseVariable: '', usernameVariable: 'GIT_SSH_USERNAME')]) {
  54. sh """[ -d ${SWARM_GIT_NAME} ] && rm -rf ${SWARM_GIT_NAME}
  55. GIT_SSH_COMMAND='ssh -i ${GIT_SSH_KEY} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' \
  56. git clone ${SWARM_GIT_URL}
  57. cd ${SWARM_GIT_NAME}
  58. echo -n ${REV_NUMBER}-${BUILD_NUMBER} > tags/${DOCKER_IMAGE}.build-version
  59. git add -A
  60. git config --global user.email "${JENKINS_MAIL}"
  61. git config --global user.name "Jenkins"
  62. git commit -m "Version update tags/lab/${DOCKER_IMAGE}.build-version = ${REV_NUMBER}-${BUILD_NUMBER}"
  63. GIT_SSH_COMMAND='ssh -i ${GIT_SSH_KEY} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' \
  64. git push origin master
  65. cd ..
  66. rm -rf ${SWARM_GIT_NAME}
  67. ls"""
  68. }
  69. }
  70. }
  71. }
  72. post {
  73. failure {
  74. mail charset: 'UTF-8',
  75. subject: "Jenkins build ERROR",
  76. mimeType: 'text/html',
  77. to: "${mailto}",
  78. 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}"
  79. }
  80. success {
  81. mail charset: 'UTF-8',
  82. subject: "Jenkins build SUSCCESS",
  83. mimeType: 'text/html',
  84. to: "${mailto}",
  85. 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}"
  86. }
  87. }
  88. }