Jenkinsfile 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. 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']]])
  40. }
  41. }
  42. stage('Install') {
  43. agent {
  44. docker {
  45. image 'node:6.9.5'
  46. args "-v /var/lib/jenkins/.npm:/tmp/.npm"
  47. reuseNode true
  48. }
  49. }
  50. steps {
  51. sh 'git config --global core.logallrefupdates false'
  52. sh 'mv app/views/external/robots.txt public/robots.txt'
  53. sh 'mv app/views/external/googlebdb0f8f7f4a17241.html public/googlebdb0f8f7f4a17241.html'
  54. sh 'npm install'
  55. sh 'npm rebuild'
  56. sh 'npm install --quiet grunt'
  57. sh 'npm install --quiet grunt-cli'
  58. sh 'ls -l node_modules/.bin'
  59. }
  60. }
  61. stage('Compile') {
  62. agent {
  63. docker {
  64. image 'node:6.9.5'
  65. reuseNode true
  66. }
  67. }
  68. steps {
  69. sh 'node_modules/.bin/grunt compile --verbose'
  70. // replace the build number placeholder for sentry
  71. sh 'node_modules/.bin/grunt version'
  72. }
  73. }
  74. stage('Smoke Test') {
  75. agent {
  76. docker {
  77. image 'node:6.9.5'
  78. reuseNode true
  79. }
  80. }
  81. steps {
  82. sh 'node_modules/.bin/grunt compile:smoke_tests'
  83. }
  84. }
  85. stage('Minify') {
  86. agent {
  87. docker {
  88. image 'node:6.9.5'
  89. reuseNode true
  90. }
  91. }
  92. steps {
  93. sh 'node_modules/.bin/grunt compile:minify'
  94. }
  95. }
  96. stage('Unit Test') {
  97. agent {
  98. docker {
  99. image 'node:6.9.5'
  100. reuseNode true
  101. }
  102. }
  103. steps {
  104. sh 'env NODE_ENV=development ./node_modules/.bin/grunt test:unit --reporter=tap'
  105. }
  106. }
  107. stage('Acceptance Tests') {
  108. steps {
  109. sh 'docker pull sharelatex/acceptance-test-runner'
  110. sh 'docker run --rm -v $(pwd):/app --env SHARELATEX_ALLOW_PUBLIC_ACCESS=true sharelatex/acceptance-test-runner'
  111. }
  112. }
  113. stage('Package') {
  114. steps {
  115. sh 'rm -rf ./node_modules/grunt*'
  116. sh 'echo ${BUILD_NUMBER} > build_number.txt'
  117. sh 'touch build.tar.gz' // Avoid tar warning about files changing during read
  118. sh 'tar -czf build.tar.gz --exclude=build.tar.gz --exclude-vcs .'
  119. }
  120. }
  121. stage('Publish') {
  122. steps {
  123. withAWS(credentials:'S3_CI_BUILDS_AWS_KEYS', region:"${S3_REGION_BUILD_ARTEFACTS}") {
  124. s3Upload(file:'build.tar.gz', bucket:"${S3_BUCKET_BUILD_ARTEFACTS}", path:"${JOB_NAME}/${BUILD_NUMBER}.tar.gz")
  125. // The deployment process uses this file to figure out the latest build
  126. s3Upload(file:'build_number.txt', bucket:"${S3_BUCKET_BUILD_ARTEFACTS}", path:"${JOB_NAME}/latest")
  127. }
  128. }
  129. }
  130. stage('Sync OSS') {
  131. when {
  132. branch 'master'
  133. }
  134. steps {
  135. sshagent (credentials: ['GIT_DEPLOY_KEY']) {
  136. sh 'git push git@github.com:sharelatex/web-sharelatex.git HEAD:master'
  137. }
  138. }
  139. }
  140. }
  141. post {
  142. failure {
  143. mail(from: "${EMAIL_ALERT_FROM}",
  144. to: "${EMAIL_ALERT_TO}",
  145. subject: "Jenkins build failed: ${JOB_NAME}:${BUILD_NUMBER}",
  146. body: "Build: ${BUILD_URL}")
  147. }
  148. }
  149. // The options directive is for configuration that applies to the whole job.
  150. options {
  151. // Only build one at a time
  152. disableConcurrentBuilds()
  153. // we'd like to make sure remove old builds, so we don't fill up our storage!
  154. buildDiscarder(logRotator(numToKeepStr:'50'))
  155. // And we'd really like to be sure that this build doesn't hang forever, so let's time it out after:
  156. timeout(time: 30, unit: 'MINUTES')
  157. }
  158. }