Jenkinsfile 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. env.BUILD_ID = 58
  45. /* Push the container to the custom Registry */
  46. dockerImage.push()
  47. dockerImage.push('latest')
  48. }
  49. }
  50. // echo 'env.BRANCH_NAME : ' + env.BRANCH_NAME
  51. // if(env.BRANCH_NAME == 'master'){
  52. // script {
  53. // app = docker.build("ptb-be:latest")
  54. // echo 'app content : ' + app
  55. // dockerImage = registryAddress + ":$BUILD_NUMBER"
  56. // echo 'dockerImage : ' + dockerImage
  57. // echo 'registryCredential : ' + registryCredential
  58. // echo 'registryAddress : ' + registryAddress
  59. // echo 'withRegistry running...'
  60. // docker.withRegistry( "http://"+registryAddress, registryCredential ) {
  61. // echo 'withRegistry inside... app.push start'
  62. // //app.push("${BUILD_NUMBER}")
  63. // app.push('ptb-be:latest')
  64. // echo 'app.push done'
  65. // echo 'withRegistry inside... app.push latest start'
  66. // app.push(latest)
  67. // echo 'withRegistry inside... app.push latest done'
  68. // }
  69. // }
  70. // }
  71. }
  72. }
  73. catch (err) {
  74. throw err
  75. }
  76. }