Jenkinsfile 3.5 KB

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