Jenkinsfile 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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('Unit Test') {
  51. agent {
  52. docker {
  53. image 'node:6.9.5'
  54. reuseNode true
  55. }
  56. }
  57. steps {
  58. sh 'make --no-print-directory test_unit MOCHA_ARGS="--reporter tap"'
  59. }
  60. }
  61. stage('Frontend Unit Test') {
  62. steps {
  63. // Spawns its own docker containers
  64. sh 'make --no-print-directory test_frontend'
  65. }
  66. }
  67. stage('Acceptance Test') {
  68. steps {
  69. // Spawns its own docker containers
  70. sh 'make --no-print-directory test_acceptance MOCHA_ARGS="--reporter tap"'
  71. }
  72. }
  73. stage('Minify') {
  74. agent {
  75. docker {
  76. image 'node:6.9.5'
  77. reuseNode true
  78. }
  79. }
  80. steps {
  81. sh 'make minify'
  82. }
  83. }
  84. stage('Package') {
  85. steps {
  86. sh 'rm -rf ./node_modules/grunt*'
  87. sh 'echo ${BUILD_NUMBER} > build_number.txt'
  88. sh 'touch build.tar.gz' // Avoid tar warning about files changing during read
  89. sh 'tar -czf build.tar.gz --exclude=build.tar.gz --exclude-vcs .'
  90. }
  91. }
  92. stage('Publish') {
  93. steps {
  94. withAWS(credentials:'S3_CI_BUILDS_AWS_KEYS', region:"${S3_REGION_BUILD_ARTEFACTS}") {
  95. s3Upload(file:'build.tar.gz', bucket:"${S3_BUCKET_BUILD_ARTEFACTS}", path:"${JOB_NAME}/${BUILD_NUMBER}.tar.gz")
  96. // The deployment process uses this file to figure out the latest build
  97. s3Upload(file:'build_number.txt', bucket:"${S3_BUCKET_BUILD_ARTEFACTS}", path:"${JOB_NAME}/latest")
  98. }
  99. }
  100. }
  101. stage('Sync OSS') {
  102. when {
  103. branch 'master'
  104. }
  105. steps {
  106. sshagent (credentials: ['GIT_DEPLOY_KEY']) {
  107. sh 'git push git@github.com:sharelatex/web-sharelatex.git HEAD:master'
  108. }
  109. }
  110. }
  111. }
  112. post {
  113. always {
  114. sh 'make clean_ci'
  115. }
  116. failure {
  117. mail(from: "${EMAIL_ALERT_FROM}",
  118. to: "${EMAIL_ALERT_TO}",
  119. subject: "Jenkins build failed: ${JOB_NAME}:${BUILD_NUMBER}",
  120. body: "Build: ${BUILD_URL}")
  121. }
  122. }
  123. // The options directive is for configuration that applies to the whole job.
  124. options {
  125. // Only build one at a time
  126. disableConcurrentBuilds()
  127. // we'd like to make sure remove old builds, so we don't fill up our storage!
  128. buildDiscarder(logRotator(numToKeepStr:'50'))
  129. // And we'd really like to be sure that this build doesn't hang forever, so let's time it out after:
  130. timeout(time: 30, unit: 'MINUTES')
  131. }
  132. }