Jenkinsfile 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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.14.1'
  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.14.1'
  29. reuseNode true
  30. }
  31. }
  32. steps {
  33. sh 'node_modules/.bin/grunt install'
  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. withCredentials([usernamePassword(credentialsId: 'S3_DOCSTORE_TEST_AWS_KEYS', passwordVariable: 'AWS_SECRET', usernameVariable: 'AWS_ID')]) {
  42. sh 'docker run --rm -e AWS_BUCKET="sl-doc-archive-testing" -e AWS_ACCESS_KEY_ID=$AWS_ID -e AWS_SECRET_ACCESS_KEY=$AWS_SECRET -v $(pwd):/app sharelatex/acceptance-test-runner'
  43. }
  44. }
  45. }
  46. stage('Package') {
  47. steps {
  48. sh 'echo ${BUILD_NUMBER} > build_number.txt'
  49. sh 'touch build.tar.gz' // Avoid tar warning about files changing during read
  50. sh 'tar -czf build.tar.gz --exclude=build.tar.gz --exclude-vcs .'
  51. }
  52. }
  53. stage('Publish') {
  54. steps {
  55. withAWS(credentials:'S3_CI_BUILDS_AWS_KEYS', region:"${S3_REGION_BUILD_ARTEFACTS}") {
  56. s3Upload(file:'build.tar.gz', bucket:"${S3_BUCKET_BUILD_ARTEFACTS}", path:"${JOB_NAME}/${BUILD_NUMBER}.tar.gz")
  57. // The deployment process uses this file to figure out the latest build
  58. s3Upload(file:'build_number.txt', bucket:"${S3_BUCKET_BUILD_ARTEFACTS}", path:"${JOB_NAME}/latest")
  59. }
  60. }
  61. }
  62. }
  63. post {
  64. failure {
  65. mail(from: "${EMAIL_ALERT_FROM}",
  66. to: "${EMAIL_ALERT_TO}",
  67. subject: "Jenkins build failed: ${JOB_NAME}:${BUILD_NUMBER}",
  68. body: "Build: ${BUILD_URL}")
  69. }
  70. }
  71. // The options directive is for configuration that applies to the whole job.
  72. options {
  73. // we'd like to make sure remove old builds, so we don't fill up our storage!
  74. buildDiscarder(logRotator(numToKeepStr:'50'))
  75. // And we'd really like to be sure that this build doesn't hang forever, so let's time it out after:
  76. timeout(time: 30, unit: 'MINUTES')
  77. }
  78. }