Jenkinsfile 3.6 KB

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