Jenkinsfile 3.7 KB

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