You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.9KB

  1. node {
  2. result="SUCCESS"
  3. color="GREEN"
  4. notify=false
  5. message="No special message"
  6. try {
  7. dockerhub_repo = 'fxinnovation/mysql'
  8. ansiColor('xterm') {
  9. stage('checkout') {
  10. // Checking out scm
  11. checkout scm
  12. // Getting current commit sha1
  13. commit_id = sh(
  14. returnStdout: true,
  15. script: "git rev-parse HEAD"
  16. ).trim()
  17. // Getting current tag or commit sha1
  18. tag_id = sh(
  19. returnStdout: true,
  20. script: "git describe --tags --exact-match || git rev-parse HEAD"
  21. ).trim()
  22. // Getting scm url
  23. scm_url = sh(
  24. returnStdout: true,
  25. script: "git config --get remote.origin.url"
  26. ).trim()
  27. }
  28. stage('pre-build') {
  29. // Verifying docker is up and running
  30. sh 'docker --version && docker images'
  31. }
  32. stage("build") {
  33. // Building Docker Image
  34. sh "docker build \
  35. --build-arg \"VCS_REF\"=\"${commit_id}\" \
  36. --build-arg \"VERSION\"=\"${tag_id}\" \
  37. --build-arg \"BUILD_DATE\"=\"\$(date -u +\"%Y-%m-%dT%H:%M:%SZ\")\" \
  38. -t ${dockerhub_repo}:${tag_id} ."
  39. }
  40. stage("test") {
  41. sh "docker inspect ${dockerhub_repo}:${tag_id}"
  42. message = "Docker build was succesfull"
  43. }
  44. }
  45. }catch (error){
  46. result="FAILED"
  47. color="RED"
  48. notify=true
  49. message=error
  50. throw (error)
  51. }finally {
  52. stage("notify"){
  53. hipchatSend (
  54. color: color,
  55. credentialId: 'jenkins-hipchat-token',
  56. message: "Job Name: ${JOB_NAME} (<a href=\"${BUILD_URL}\">Open</a>)<br /> \
  57. Job Status: ${result} <br /> \
  58. Job Message: <br /><pre>${message}</pre>",
  59. room: '942680',
  60. notify: notify,
  61. sendAs: 'New-Jenkins',
  62. server: 'api.hipchat.com',
  63. v2enabled: false
  64. )
  65. }
  66. }
  67. }