Jenkinsfile 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. pipeline {
  2. agent any
  3. environment {
  4. HOME = "/tmp"
  5. }
  6. triggers {
  7. pollSCM('* * * * *')
  8. cron('@daily')
  9. }
  10. stages {
  11. stage('Set up') {
  12. agent {
  13. docker {
  14. image 'node:6.9.5'
  15. reuseNode true
  16. }
  17. }
  18. steps {
  19. // we need to disable logallrefupdates, else git clones during the npm install will require git to lookup the user id
  20. // which does not exist in the container's /etc/passwd file, causing the clone to fail.
  21. sh 'git config --global core.logallrefupdates false'
  22. sh 'rm -rf node_modules/*'
  23. }
  24. }
  25. stage('Clone Dependencies') {
  26. steps {
  27. sh 'rm -rf public/brand modules'
  28. checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'public/brand'], [$class: 'CloneOption', shallow: true]], userRemoteConfigs: [[credentialsId: 'GIT_DEPLOY_KEY', url: 'git@github.com:sharelatex/brand-sharelatex']]])
  29. checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'app/views/external'], [$class: 'CloneOption', shallow: true]], userRemoteConfigs: [[credentialsId: 'GIT_DEPLOY_KEY', url: 'git@github.com:sharelatex/external-pages-sharelatex']]])
  30. checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'modules'], [$class: 'CloneOption', shallow: true]], userRemoteConfigs: [[credentialsId: 'GIT_DEPLOY_KEY', url: 'git@github.com:sharelatex/web-sharelatex-modules']]])
  31. checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'modules/admin-panel'], [$class: 'CloneOption', shallow: true]], userRemoteConfigs: [[credentialsId: 'GIT_DEPLOY_KEY', url: 'git@github.com:sharelatex/admin-panel']]])
  32. checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'modules/groovehq'], [$class: 'CloneOption', shallow: true]], userRemoteConfigs: [[credentialsId: 'GIT_DEPLOY_KEY', url: 'git@bitbucket.org:sharelatex/groovehq']]])
  33. checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'modules/references-search'], [$class: 'CloneOption', shallow: true]], userRemoteConfigs: [[credentialsId: 'GIT_DEPLOY_KEY', url: 'git@bitbucket.org:sharelatex/references-search.git']]])
  34. checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'modules/tpr-webmodule'], [$class: 'CloneOption', shallow: true]], userRemoteConfigs: [[credentialsId: 'GIT_DEPLOY_KEY', url: 'git@github.com:sharelatex/tpr-webmodule.git ']]])
  35. checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'modules/learn-wiki'], [$class: 'CloneOption', shallow: true]], userRemoteConfigs: [[credentialsId: 'GIT_DEPLOY_KEY', url: 'git@bitbucket.org:sharelatex/learn-wiki-web-module.git']]])
  36. checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'modules/templates'], [$class: 'CloneOption', shallow: true]], userRemoteConfigs: [[credentialsId: 'GIT_DEPLOY_KEY', url: 'git@github.com:sharelatex/templates-webmodule.git']]])
  37. checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'modules/track-changes'], [$class: 'CloneOption', shallow: true]], userRemoteConfigs: [[credentialsId: 'GIT_DEPLOY_KEY', url: 'git@github.com:sharelatex/track-changes-web-module.git']]])
  38. checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'modules/overleaf-integration'], [$class: 'CloneOption', shallow: true]], userRemoteConfigs: [[credentialsId: 'GIT_DEPLOY_KEY', url: 'git@github.com:sharelatex/overleaf-integration-web-module.git']]])
  39. }
  40. }
  41. stage('Install') {
  42. agent {
  43. docker {
  44. image 'node:6.9.5'
  45. args "-v /var/lib/jenkins/.npm:/tmp/.npm"
  46. reuseNode true
  47. }
  48. }
  49. steps {
  50. sh 'git config --global core.logallrefupdates false'
  51. sh 'mv app/views/external/robots.txt public/robots.txt'
  52. sh 'mv app/views/external/googlebdb0f8f7f4a17241.html public/googlebdb0f8f7f4a17241.html'
  53. sh 'npm install'
  54. sh 'npm rebuild'
  55. sh 'npm install --quiet grunt'
  56. sh 'npm install --quiet grunt-cli'
  57. sh 'ls -l node_modules/.bin'
  58. }
  59. }
  60. stage('Compile') {
  61. agent {
  62. docker {
  63. image 'node:6.9.5'
  64. reuseNode true
  65. }
  66. }
  67. steps {
  68. sh 'node_modules/.bin/grunt compile --verbose'
  69. // replace the build number placeholder for sentry
  70. sh 'node_modules/.bin/grunt version'
  71. }
  72. }
  73. stage('Smoke Test') {
  74. agent {
  75. docker {
  76. image 'node:6.9.5'
  77. reuseNode true
  78. }
  79. }
  80. steps {
  81. sh 'node_modules/.bin/grunt compile:smoke_tests'
  82. }
  83. }
  84. stage('Minify') {
  85. agent {
  86. docker {
  87. image 'node:6.9.5'
  88. reuseNode true
  89. }
  90. }
  91. steps {
  92. sh 'node_modules/.bin/grunt compile:minify'
  93. }
  94. }
  95. stage('Unit Test') {
  96. agent {
  97. docker {
  98. image 'node:6.9.5'
  99. reuseNode true
  100. }
  101. }
  102. steps {
  103. sh 'env NODE_ENV=development ./node_modules/.bin/grunt test:unit --reporter=tap'
  104. }
  105. }
  106. stage('Acceptance Tests') {
  107. steps {
  108. sh 'docker pull sharelatex/acceptance-test-runner'
  109. sh 'docker run --rm -v $(pwd):/app --env SHARELATEX_ALLOW_PUBLIC_ACCESS=true sharelatex/acceptance-test-runner'
  110. }
  111. }
  112. stage('Package') {
  113. steps {
  114. sh 'rm -rf ./node_modules/grunt*'
  115. sh 'echo ${BUILD_NUMBER} > build_number.txt'
  116. sh 'touch build.tar.gz' // Avoid tar warning about files changing during read
  117. sh 'tar -czf build.tar.gz --exclude=build.tar.gz --exclude-vcs .'
  118. }
  119. }
  120. stage('Publish') {
  121. steps {
  122. withAWS(credentials:'S3_CI_BUILDS_AWS_KEYS', region:"${S3_REGION_BUILD_ARTEFACTS}") {
  123. s3Upload(file:'build.tar.gz', bucket:"${S3_BUCKET_BUILD_ARTEFACTS}", path:"${JOB_NAME}/${BUILD_NUMBER}.tar.gz")
  124. // The deployment process uses this file to figure out the latest build
  125. s3Upload(file:'build_number.txt', bucket:"${S3_BUCKET_BUILD_ARTEFACTS}", path:"${JOB_NAME}/latest")
  126. }
  127. }
  128. }
  129. stage('Sync OSS') {
  130. when {
  131. branch 'master'
  132. }
  133. steps {
  134. sshagent (credentials: ['GIT_DEPLOY_KEY']) {
  135. sh 'git push git@github.com:sharelatex/web-sharelatex.git HEAD:master'
  136. }
  137. }
  138. }
  139. }
  140. post {
  141. failure {
  142. mail(from: "${EMAIL_ALERT_FROM}",
  143. to: "${EMAIL_ALERT_TO}",
  144. subject: "Jenkins build failed: ${JOB_NAME}:${BUILD_NUMBER}",
  145. body: "Build: ${BUILD_URL}")
  146. }
  147. }
  148. // The options directive is for configuration that applies to the whole job.
  149. options {
  150. // Only build one at a time
  151. disableConcurrentBuilds()
  152. // we'd like to make sure remove old builds, so we don't fill up our storage!
  153. buildDiscarder(logRotator(numToKeepStr:'50'))
  154. // And we'd really like to be sure that this build doesn't hang forever, so let's time it out after:
  155. timeout(time: 30, unit: 'MINUTES')
  156. }
  157. }