Jenkinsfile 8.2 KB

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