Jenkinsfile 6.9 KB

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