Jenkinsfile 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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('Install modules') {
  13. steps {
  14. sshagent (credentials: ['GIT_DEPLOY_KEY']) {
  15. sh 'bin/install_modules'
  16. }
  17. }
  18. }
  19. stage('Install') {
  20. agent {
  21. docker {
  22. image 'node:6.9.5'
  23. args "-v /var/lib/jenkins/.npm:/tmp/.npm"
  24. reuseNode true
  25. }
  26. }
  27. steps {
  28. sh 'git config --global core.logallrefupdates false'
  29. sh 'rm -rf node_modules/'
  30. sh 'npm install --quiet'
  31. sh 'npm rebuild'
  32. // It's too easy to end up shrinkwrapping to an outdated version of translations.
  33. // Ensure translations are always latest, regardless of shrinkwrap
  34. sh 'npm install git+https://github.com/sharelatex/translations-sharelatex.git#master'
  35. }
  36. }
  37. stage('Compile') {
  38. agent {
  39. docker {
  40. image 'node:6.9.5'
  41. reuseNode true
  42. }
  43. }
  44. steps {
  45. sh 'make clean compile_full'
  46. // replace the build number placeholder for sentry
  47. sh 'node_modules/.bin/grunt version'
  48. }
  49. }
  50. stage('Lint') {
  51. agent {
  52. docker {
  53. image 'node:6.9.5'
  54. reuseNode true
  55. }
  56. }
  57. steps {
  58. sh 'make --no-print-directory lint'
  59. }
  60. }
  61. stage('Unit Test') {
  62. agent {
  63. docker {
  64. image 'node:6.9.5'
  65. reuseNode true
  66. }
  67. }
  68. steps {
  69. sh 'make --no-print-directory test_unit MOCHA_ARGS="--reporter tap"'
  70. }
  71. }
  72. stage('Frontend Unit Test') {
  73. steps {
  74. // Spawns its own docker containers
  75. sh 'make --no-print-directory test_frontend'
  76. }
  77. }
  78. stage('Acceptance Test') {
  79. steps {
  80. // Spawns its own docker containers
  81. sh 'make --no-print-directory test_acceptance MOCHA_ARGS="--reporter tap"'
  82. }
  83. }
  84. stage('Minify') {
  85. agent {
  86. docker {
  87. image 'node:6.9.5'
  88. reuseNode true
  89. }
  90. }
  91. steps {
  92. sh 'WEBPACK_ENV=production make minify'
  93. }
  94. }
  95. stage('Package') {
  96. steps {
  97. sh 'rm -rf ./node_modules/grunt*'
  98. sh 'echo ${BUILD_NUMBER} > build_number.txt'
  99. sh 'touch build.tar.gz' // Avoid tar warning about files changing during read
  100. sh 'tar -czf build.tar.gz --exclude=build.tar.gz --exclude-vcs .'
  101. }
  102. }
  103. stage('Publish') {
  104. steps {
  105. withAWS(credentials:'S3_CI_BUILDS_AWS_KEYS', region:"${S3_REGION_BUILD_ARTEFACTS}") {
  106. s3Upload(file:'build.tar.gz', bucket:"${S3_BUCKET_BUILD_ARTEFACTS}", path:"${JOB_NAME}/${BUILD_NUMBER}.tar.gz")
  107. // The deployment process uses this file to figure out the latest build
  108. s3Upload(file:'build_number.txt', bucket:"${S3_BUCKET_BUILD_ARTEFACTS}", path:"${JOB_NAME}/latest")
  109. }
  110. }
  111. }
  112. stage('Sync OSS') {
  113. when {
  114. branch 'master'
  115. }
  116. steps {
  117. sshagent (credentials: ['GIT_DEPLOY_KEY']) {
  118. sh 'git push git@github.com:sharelatex/web-sharelatex.git HEAD:master'
  119. }
  120. }
  121. }
  122. }
  123. post {
  124. always {
  125. sh 'make clean_ci'
  126. }
  127. failure {
  128. mail(from: "${EMAIL_ALERT_FROM}",
  129. to: "${EMAIL_ALERT_TO}",
  130. subject: "Jenkins build failed: ${JOB_NAME}:${BUILD_NUMBER}",
  131. body: "Build: ${BUILD_URL}")
  132. }
  133. }
  134. // The options directive is for configuration that applies to the whole job.
  135. options {
  136. // Only build one at a time
  137. disableConcurrentBuilds()
  138. // we'd like to make sure remove old builds, so we don't fill up our storage!
  139. buildDiscarder(logRotator(numToKeepStr:'50'))
  140. // And we'd really like to be sure that this build doesn't hang forever, so let's time it out after:
  141. timeout(time: 30, unit: 'MINUTES')
  142. }
  143. }