Jenkinsfile 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 = "https://registry.sidali.sixsenz.net"
  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. // echo 'env.BRANCH_NAME : ' + env.BRANCH_NAME
  50. // if(env.BRANCH_NAME == 'master'){
  51. // script {
  52. // app = docker.build("ptb-be:latest")
  53. // echo 'app content : ' + app
  54. // dockerImage = registryAddress + ":$BUILD_NUMBER"
  55. // echo 'dockerImage : ' + dockerImage
  56. // echo 'registryCredential : ' + registryCredential
  57. // echo 'registryAddress : ' + registryAddress
  58. // echo 'withRegistry running...'
  59. // docker.withRegistry( "http://"+registryAddress, registryCredential ) {
  60. // echo 'withRegistry inside... app.push start'
  61. // //app.push("${BUILD_NUMBER}")
  62. // app.push('ptb-be:latest')
  63. // echo 'app.push done'
  64. // echo 'withRegistry inside... app.push latest start'
  65. // app.push(latest)
  66. // echo 'withRegistry inside... app.push latest done'
  67. // }
  68. // }
  69. // }
  70. }
  71. }
  72. catch (err) {
  73. throw err
  74. }
  75. }