Jenkinsfile 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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: '*/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']]])
  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 --quiet 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('Test') {
  66. steps {
  67. sh 'make ci'
  68. }
  69. }
  70. stage('Compile') {
  71. agent {
  72. docker {
  73. image 'node:6.9.5'
  74. reuseNode true
  75. }
  76. }
  77. steps {
  78. sh 'node_modules/.bin/grunt compile compile:tests --verbose'
  79. // replace the build number placeholder for sentry
  80. sh 'node_modules/.bin/grunt version'
  81. }
  82. }
  83. stage('Smoke Test') {
  84. agent {
  85. docker {
  86. image 'node:6.9.5'
  87. reuseNode true
  88. }
  89. }
  90. steps {
  91. sh 'node_modules/.bin/grunt compile:smoke_tests'
  92. }
  93. }
  94. stage('Minify') {
  95. agent {
  96. docker {
  97. image 'node:6.9.5'
  98. reuseNode true
  99. }
  100. }
  101. steps {
  102. sh 'node_modules/.bin/grunt compile:minify'
  103. }
  104. }
  105. stage('Package') {
  106. steps {
  107. sh 'rm -rf ./node_modules/grunt*'
  108. sh 'echo ${BUILD_NUMBER} > build_number.txt'
  109. sh 'touch build.tar.gz' // Avoid tar warning about files changing during read
  110. sh 'tar -czf build.tar.gz --exclude=build.tar.gz --exclude-vcs .'
  111. }
  112. }
  113. stage('Publish') {
  114. steps {
  115. withAWS(credentials:'S3_CI_BUILDS_AWS_KEYS', region:"${S3_REGION_BUILD_ARTEFACTS}") {
  116. s3Upload(file:'build.tar.gz', bucket:"${S3_BUCKET_BUILD_ARTEFACTS}", path:"${JOB_NAME}/${BUILD_NUMBER}.tar.gz")
  117. // The deployment process uses this file to figure out the latest build
  118. s3Upload(file:'build_number.txt', bucket:"${S3_BUCKET_BUILD_ARTEFACTS}", path:"${JOB_NAME}/latest")
  119. }
  120. }
  121. }
  122. stage('Sync OSS') {
  123. when {
  124. branch 'master'
  125. }
  126. steps {
  127. sshagent (credentials: ['GIT_DEPLOY_KEY']) {
  128. sh 'git push git@github.com:sharelatex/web-sharelatex.git HEAD:master'
  129. }
  130. }
  131. }
  132. }
  133. post {
  134. always {
  135. sh 'make ci_clean'
  136. }
  137. failure {
  138. mail(from: "${EMAIL_ALERT_FROM}",
  139. to: "${EMAIL_ALERT_TO}",
  140. subject: "Jenkins build failed: ${JOB_NAME}:${BUILD_NUMBER}",
  141. body: "Build: ${BUILD_URL}")
  142. }
  143. }
  144. // The options directive is for configuration that applies to the whole job.
  145. options {
  146. // Only build one at a time
  147. disableConcurrentBuilds()
  148. // we'd like to make sure remove old builds, so we don't fill up our storage!
  149. buildDiscarder(logRotator(numToKeepStr:'50'))
  150. // And we'd really like to be sure that this build doesn't hang forever, so let's time it out after:
  151. timeout(time: 30, unit: 'MINUTES')
  152. }
  153. }