Jenkinsfile 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import java.text.SimpleDateFormat
  2. pipeline {
  3. agent {
  4. label "dev-winservice"
  5. }
  6. options {
  7. timeout(time: 3, unit: 'HOURS')
  8. }
  9. environment {
  10. JENKINS_MAIL='jenkins@sdsys.ru'
  11. REV_NUMBER=''
  12. }
  13. parameters {
  14. string(
  15. name: "mailto",
  16. defaultValue: "labportal@sdsys.ru",
  17. description: "Email which has to be notified."
  18. )
  19. }
  20. stages {
  21. stage("Build docker image") {
  22. steps {
  23. // Checkout repository
  24. powershell 'svn.exe checkout svn://192.168.21.250/programs/trunk/Services/Analis/Win64 Infoclinica --username public --password "sds#7753435"'
  25. // Discover revision number
  26. script {
  27. REV_NUMBER = powershell(returnStdout: true, script: 'svn info --show-item last-changed-revision .\\Infoclinica').trim()
  28. echo "Last-Changed-Revision number is '$REV_NUMBER'"
  29. }
  30. powershell """
  31. Set-PSDebug -Trace 1
  32. pwd
  33. move-Item -Path .\\Infoclinica\\.svn -Destination ..\\svn
  34. docker build -t registry.infoclinica.ru:5000/lab/analis-service:${REV_NUMBER}-${BUILD_NUMBER} .
  35. move-Item -Path ..\\svn -Destination .\\Infoclinica\\.svn
  36. """
  37. }
  38. }
  39. stage("Push to registry"){
  40. steps {
  41. powershell """
  42. Set-PSDebug -Trace 1
  43. docker tag registry.infoclinica.ru:5000/lab/analis-service:${REV_NUMBER}-${BUILD_NUMBER} registry.infoclinica.ru:5000/lab/analis-service:latest
  44. docker push registry.infoclinica.ru:5000/lab/analis-service:${REV_NUMBER}-${BUILD_NUMBER}
  45. docker push registry.infoclinica.ru:5000/lab/analis-service:latest
  46. """
  47. }
  48. }
  49. }
  50. post {
  51. failure {
  52. mail charset: 'UTF-8',
  53. subject: "Jenkins Analis Server docker image build ERROR",
  54. mimeType: 'text/html',
  55. to: "${mailto}",
  56. body: "<b>ATTENTION!!!</b> <br><br><br> Jenkins job failed. <br>Project Name: ${env.JOB_NAME} <br>Build Number: ${env.BUILD_NUMBER} <br>Build Tag: <b>${REV_NUMBER}-${env.BUILD_NUMBER}</b><br>URL Build:${RUN_DISPLAY_URL}"
  57. }
  58. success {
  59. mail charset: 'UTF-8',
  60. subject: "Jenkins Analis Server docker image build SUCCESS",
  61. mimeType: 'text/html',
  62. to: "${mailto}",
  63. body: "<b>Congradulations!!!</b> <br><br><br> Jenkins job <b>succefully</b> finished.\n\n <br>Project Name: ${env.JOB_NAME} <br>\nBuild Number: ${env.BUILD_NUMBER} <br>\nBuild Tag: <b>${REV_NUMBER}-${env.BUILD_NUMBER}</b><br>\nURL Build: ${RUN_DISPLAY_URL}"
  64. }
  65. }
  66. }