Jenkinsfile 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. pipeline {
  2. agent any
  3. triggers {
  4. pollSCM('* * * * *')
  5. cron('@daily')
  6. }
  7. stages {
  8. stage('Install') {
  9. agent {
  10. docker {
  11. image 'node:6.9.5'
  12. args "-v /var/lib/jenkins/.npm:/tmp/.npm -e HOME=/tmp"
  13. reuseNode true
  14. }
  15. }
  16. steps {
  17. // we need to disable logallrefupdates, else git clones during the npm install will require git to lookup the user id
  18. // which does not exist in the container's /etc/passwd file, causing the clone to fail.
  19. sh 'git config --global core.logallrefupdates false'
  20. sh 'rm -fr node_modules'
  21. sh 'npm install && npm rebuild'
  22. sh 'npm install --quiet grunt-cli'
  23. }
  24. }
  25. stage('Compile and Test') {
  26. agent {
  27. docker {
  28. image 'node:6.9.5'
  29. reuseNode true
  30. }
  31. }
  32. steps {
  33. sh 'node_modules/.bin/grunt compile'
  34. sh 'node_modules/.bin/grunt compile:acceptance_tests'
  35. sh 'NODE_ENV=development node_modules/.bin/grunt test:unit'
  36. }
  37. }
  38. stage('Acceptance Tests') {
  39. steps {
  40. sh 'docker pull sharelatex/acceptance-test-runner'
  41. sh 'docker run --rm -e SHARELATEX_ENABLE_PROJECT_HISTORY=true -v $(pwd):/app sharelatex/acceptance-test-runner'
  42. }
  43. }
  44. stage('Package') {
  45. steps {
  46. sh 'echo ${BUILD_NUMBER} > build_number.txt'
  47. sh 'touch build.tar.gz' // Avoid tar warning about files changing during read
  48. sh 'tar -czf build.tar.gz --exclude=build.tar.gz --exclude-vcs .'
  49. }
  50. }
  51. stage('Publish') {
  52. steps {
  53. withAWS(credentials:'S3_CI_BUILDS_AWS_KEYS', region:"${S3_REGION_BUILD_ARTEFACTS}") {
  54. s3Upload(file:'build.tar.gz', bucket:"${S3_BUCKET_BUILD_ARTEFACTS}", path:"${JOB_NAME}/${BUILD_NUMBER}.tar.gz")
  55. // The deployment process uses this file to figure out the latest build
  56. s3Upload(file:'build_number.txt', bucket:"${S3_BUCKET_BUILD_ARTEFACTS}", path:"${JOB_NAME}/latest")
  57. }
  58. }
  59. }
  60. stage('Sync OSS') {
  61. when {
  62. branch 'master'
  63. }
  64. steps {
  65. sshagent (credentials: ['GIT_DEPLOY_KEY']) {
  66. sh 'git push git@github.com:sharelatex/document-updater-sharelatex.git HEAD:master'
  67. }
  68. }
  69. }
  70. }
  71. post {
  72. failure {
  73. mail(from: "${EMAIL_ALERT_FROM}",
  74. to: "${EMAIL_ALERT_TO}",
  75. subject: "Jenkins build failed: ${JOB_NAME}:${BUILD_NUMBER}",
  76. body: "Build: ${BUILD_URL}")
  77. }
  78. }
  79. // The options directive is for configuration that applies to the whole job.
  80. options {
  81. // we'd like to make sure remove old builds, so we don't fill up our storage!
  82. buildDiscarder(logRotator(numToKeepStr:'50'))
  83. // And we'd really like to be sure that this build doesn't hang forever, so let's time it out after:
  84. timeout(time: 30, unit: 'MINUTES')
  85. }
  86. }