Jenkinsfile 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. node{
  2. stage('Prepare Node and NPM') { // confirm nodejs plugin and setting
  3. env.NODEJS_HOME = "${tool 'NodeJS'}"
  4. //on linux / mac
  5. env.PATH="${env.NODEJS_HOME}/bin:${env.PATH}"
  6. // on windows
  7. // env.PATH="${env.NODEJS_HOME};${env.PATH}"
  8. sh 'npm --version'
  9. }
  10. stage('checkout'){
  11. deleteDir()
  12. checkout scm
  13. echo 'Pulling..................' + env.BRANCH_NAME
  14. }
  15. stage('Stop Container'){
  16. sh 'docker ps | grep "workflow_" -v | awk -F " " \'{if(NR>1)print $1}\' | xargs docker kill | xargs docker rm || true'
  17. sh 'docker system prune -f'
  18. }
  19. //stage('Build Container')
  20. // {
  21. // imageApache=docker.build('server-apache-dev', '--no-cache -f build/docker/apache/Dockerfile .')
  22. // imageSql=docker.build('server-mysql-dev', '--no-cache -f build/docker/mysql/Dockerfile .')
  23. // containerMysql=imageSql.run('--name server-mysql-dev')
  24. // containerApache=imageApache.run('-p 8080:80 --link server-mysql-dev:mysql')
  25. // }
  26. // stage('Waiting Container'){
  27. // waitUntil{
  28. // try{
  29. // sh "docker exec ${containerApache.id} php -v"
  30. // return true
  31. // } catch(Exception $e){
  32. // return false
  33. // }
  34. // }
  35. // }
  36. stage('stage 1bis'){
  37. sh 'docker -v'
  38. sh 'docker ps'
  39. }
  40. stage('stage 2bis'){
  41. sh 'ls -ls'
  42. }
  43. <<<<<<< HEAD
  44. // stage('Test'){
  45. =======
  46. stage('Test')
  47. {
  48. >>>>>>> test
  49. dir("${env.WORKSPACE}/angular-client")
  50. {
  51. // sh 'npm i @angular-devkit/build-angular'
  52. // try
  53. // {
  54. // sh 'npm run test-ci'
  55. // }
  56. // catch(err)
  57. // {
  58. // sh 'echo TEST FAILED'
  59. // junit 'target/surefire-reports/TESTS-TestSuite.xml/*.xml'
  60. // throw err
  61. // }
  62. def karma = docker.image('trion/ng-cli-karma')
  63. karma.pull()
  64. try
  65. {
  66. karma.run(' -u $(id -u) -v ${WORKSPACE}:/app trion/ng-cli-karma ')
  67. karma.inside
  68. {
  69. sh 'npm install'
  70. try
  71. {
  72. sh ('karma start karma.conf.js')
  73. }
  74. catch(err)
  75. {
  76. sh 'echo TEST FAILED'
  77. step([$class: 'JUnitResultArchiver', testResults: 'target/surefire-reports/TESTS-TestSuite.xml/*.xml', healthScaleFactor: 1.0])
  78. throw err
  79. }
  80. sh 'echo DO SOMETHING ELSE AFTER TEST'
  81. }
  82. sh 'ls -al '
  83. }
  84. catch(err)
  85. {
  86. sh 'echo RUN DOCKER FAILED'
  87. throw err
  88. }
  89. }
  90. }
  91. // def imageApache = stage("Build apache preprod")
  92. // {
  93. // docker.build("server-apache-preprod", "--no-cache --label traefik.enable=true --label traefik.http.routers.server-apache-preprod.rule='Host(`angular-preprod.foodgame.fr`)' --label traefik.http.routers.server-apache-preprod.entrypoints=websecure --label traefik.http.routers.server-apache-preprod.tls.certresolver=myresolver -f build/docker/httpd/Dockerfile .")
  94. // }
  95. // def imageExpress = stage("Build express preprod")
  96. // {
  97. // docker.build("server-express-preprod", "--no-cache -f express-server/Dockerfile express-server")
  98. // }
  99. /*stage("Run Container express preprod")
  100. {
  101. containerSql=imageExpress.run("--name server-express-preprod -v /var/log:/var/www/app/log/root --link database_preprod:mongo --network=web")
  102. }
  103. stage("Run Container apache preprod")
  104. {
  105. containerApache=imageApache.run("--name server-apache-preprod --link server-mysql-preprod:mysql --network=web")
  106. }*/
  107. /*stage("Run Container express preprod")
  108. {
  109. containerSql=imageExpress.run("--name server-express-preprod -v /home/projet/fatboar/${e}/mysql:/var/lib/mysql --network=web")
  110. }
  111. stage("Run Container apache preprod")
  112. {
  113. containerApache=imageApache.run("--name server-apache-preprod --link server-mysql-preprod:mysql --network=web")
  114. }*/
  115. // stage("Push preprod images to nexus")
  116. // {
  117. // /*docker.withRegistry('http://localhost:8083','885ef60c-9352-489a-bd1c-e4b695747c21')
  118. // {
  119. // imageApache.push('latest')
  120. // imageExpress.push('latest')
  121. // }*/
  122. // }
  123. // stage('SonarQube analysis')
  124. // {
  125. // def scannerHome = tool name: 'SonarQube Scanner', type: 'hudson.plugins.sonar.SonarRunnerInstallation';
  126. // withSonarQubeEnv('SonarQube')
  127. // {
  128. // // If you have configured more than one global server connection, you can specify its name
  129. // sh "${scannerHome}/bin/sonar-scanner \
  130. // -Dsonar.projectKey=FatboarProject \
  131. // -Dsonar.sources=. \
  132. // -Dsonar.host.url=https://sonarqube.foodgame.fr \
  133. // -Dsonar.login=sqp_09ee9072c917af8212864baf0f75c950afc14c64"
  134. // }
  135. // }
  136. <<<<<<< HEAD
  137. stage('Build Docker MEAN Stack(PreProduction Deployment)')
  138. =======
  139. stage('Build Docker MEAN Stack(Test Deployment)')
  140. >>>>>>> test
  141. {
  142. sh 'docker-compose -v'
  143. sh 'docker-compose build'
  144. sh 'docker-compose up -d'
  145. }
  146. stage('Fin du Pipeline')
  147. {
  148. sh 'echo "Félicitation tout c\'est bien déroulé!"'
  149. }
  150. }