Jenkinsfile 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. 1. added
  3. client_max_body_size 0;
  4. to avoid 413 error
  5. */
  6. node {
  7. def app
  8. def registryAddress
  9. def registryCredential
  10. try {
  11. // environment {
  12. registryAddress = "http://registry.sidali-prod.vertibiz.com"
  13. registryCredential = 'DockerRegistry-ID'
  14. // }
  15. stage('Checkout') {
  16. checkout scm
  17. }
  18. stage('Initialize'){
  19. def dockerHome = tool 'myDocker'
  20. env.PATH = "${dockerHome}/bin:${env.PATH}"
  21. }
  22. stage('Environment') {
  23. sh 'git --version'
  24. echo "Branch: master"
  25. sh 'docker -v'
  26. sh 'printenv'
  27. }
  28. stage('Test Build'){
  29. sh 'docker build -t ptb-be -f dockerfile .'
  30. }
  31. stage('Build Deploy '){
  32. // // now you are on slave labeled with 'label'
  33. // def workspace = WORKSPACE
  34. // // ${workspace} will now contain an absolute path to job workspace on slave
  35. // workspace = env.WORKSPACE
  36. // // ${workspace} will still contain an absolute path to job workspace on slave
  37. // // When using a GString at least later Jenkins versions could only handle the env.WORKSPACE variant:
  38. // echo "Current workspace is ${env.WORKSPACE}"
  39. // // the current Jenkins instances will support the short syntax, too:
  40. // echo "Current workspace is $WORKSPACE"
  41. docker.withTool("myDocker"){
  42. docker.withRegistry(registryAddress, registryCredential) {
  43. def dockerImage = docker.build("ptb-be:${env.BUILD_ID}")
  44. /* Push the container to the custom Registry */
  45. dockerImage.push()
  46. dockerImage.push('latest')
  47. }
  48. }
  49. dir('/var/docker') {
  50. sh 'docker-compose up -d'
  51. }
  52. // echo 'env.BRANCH_NAME : ' + env.BRANCH_NAME
  53. // if(env.BRANCH_NAME == 'master'){
  54. // script {
  55. // app = docker.build("ptb-be:latest")
  56. // echo 'app content : ' + app
  57. // dockerImage = registryAddress + ":$BUILD_NUMBER"
  58. // echo 'dockerImage : ' + dockerImage
  59. // echo 'registryCredential : ' + registryCredential
  60. // echo 'registryAddress : ' + registryAddress
  61. // echo 'withRegistry running...'
  62. // docker.withRegistry( "http://"+registryAddress, registryCredential ) {
  63. // echo 'withRegistry inside... app.push start'
  64. // //app.push("${BUILD_NUMBER}")
  65. // app.push('ptb-be:latest')
  66. // echo 'app.push done'
  67. // echo 'withRegistry inside... app.push latest start'
  68. // app.push(latest)
  69. // echo 'withRegistry inside... app.push latest done'
  70. // }
  71. // }
  72. // }
  73. }
  74. }
  75. catch (err) {
  76. throw err
  77. }
  78. }