Jenkinsfile 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. pipeline {
  2. agent {
  3. docker {
  4. image 'node:6.9.5'
  5. args "-v /var/lib/jenkins/.npm:/tmp/.npm"
  6. }
  7. }
  8. environment {
  9. HOME = "/tmp"
  10. }
  11. triggers {
  12. pollSCM('* * * * *')
  13. cron('@daily')
  14. }
  15. stages {
  16. stage('Set up') {
  17. steps {
  18. // we need to disable logallrefupdates, else git clones during the npm install will require git to lookup the user id
  19. // which does not exist in the container's /etc/passwd file, causing the clone to fail.
  20. sh 'git config --global core.logallrefupdates false'
  21. sh 'rm -rf node_modules/*'
  22. }
  23. }
  24. stage('Clone Dependencies') {
  25. steps {
  26. sh 'rm -rf public/brand modules'
  27. checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'public/brand'], [$class: 'CloneOption', shallow: true]], userRemoteConfigs: [[credentialsId: 'GIT_DEPLOY_KEY', url: 'git@github.com:sharelatex/brand-sharelatex']]])
  28. checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'app/views/external'], [$class: 'CloneOption', shallow: true]], userRemoteConfigs: [[credentialsId: 'GIT_DEPLOY_KEY', url: 'git@github.com:sharelatex/external-pages-sharelatex']]])
  29. checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'modules'], [$class: 'CloneOption', shallow: true]], userRemoteConfigs: [[credentialsId: 'GIT_DEPLOY_KEY', url: 'git@github.com:sharelatex/web-sharelatex-modules']]])
  30. checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'modules/admin-panel'], [$class: 'CloneOption', shallow: true]], userRemoteConfigs: [[credentialsId: 'GIT_DEPLOY_KEY', url: 'git@github.com:sharelatex/admin-panel']]])
  31. checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'modules/groovehq'], [$class: 'CloneOption', shallow: true]], userRemoteConfigs: [[credentialsId: 'GIT_DEPLOY_KEY', url: 'git@bitbucket.org:sharelatex/groovehq']]])
  32. checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'modules/references-search'], [$class: 'CloneOption', shallow: true]], userRemoteConfigs: [[credentialsId: 'GIT_DEPLOY_KEY', url: 'git@bitbucket.org:sharelatex/references-search.git']]])
  33. checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'modules/tpr-webmodule'], [$class: 'CloneOption', shallow: true]], userRemoteConfigs: [[credentialsId: 'GIT_DEPLOY_KEY', url: 'git@github.com:sharelatex/tpr-webmodule.git ']]])
  34. checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'modules/learn-wiki'], [$class: 'CloneOption', shallow: true]], userRemoteConfigs: [[credentialsId: 'GIT_DEPLOY_KEY', url: 'git@bitbucket.org:sharelatex/learn-wiki-web-module.git']]])
  35. checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'modules/templates'], [$class: 'CloneOption', shallow: true]], userRemoteConfigs: [[credentialsId: 'GIT_DEPLOY_KEY', url: 'git@github.com:sharelatex/templates-webmodule.git']]])
  36. checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'modules/track-changes'], [$class: 'CloneOption', shallow: true]], userRemoteConfigs: [[credentialsId: 'GIT_DEPLOY_KEY', url: 'git@github.com:sharelatex/track-changes-web-module.git']]])
  37. }
  38. }
  39. stage('Install') {
  40. steps {
  41. sh 'mv app/views/external/robots.txt public/robots.txt'
  42. sh 'mv app/views/external/googlebdb0f8f7f4a17241.html public/googlebdb0f8f7f4a17241.html'
  43. sh 'npm install'
  44. sh 'npm rebuild'
  45. sh 'npm install --quiet grunt'
  46. sh 'npm install --quiet grunt-cli'
  47. sh 'ls -l node_modules/.bin'
  48. }
  49. }
  50. stage('Compile') {
  51. steps {
  52. sh 'node_modules/.bin/grunt compile --verbose'
  53. }
  54. }
  55. stage('Smoke Test') {
  56. steps {
  57. sh 'node_modules/.bin/grunt compile:smoke_tests'
  58. }
  59. }
  60. stage('Minify') {
  61. steps {
  62. sh 'node_modules/.bin/grunt compile:minify'
  63. }
  64. }
  65. stage('Unit Test') {
  66. steps {
  67. sh 'env NODE_ENV=development ./node_modules/.bin/grunt test:unit --reporter=tap'
  68. }
  69. }
  70. stage('Package') {
  71. steps {
  72. sh 'rm -rf ./node_modules/grunt*'
  73. sh 'echo ${BUILD_NUMBER} > build_number.txt'
  74. sh 'touch build.tar.gz' // Avoid tar warning about files changing during read
  75. sh 'tar -czf build.tar.gz --exclude=build.tar.gz --exclude-vcs .'
  76. }
  77. }
  78. stage('Publish') {
  79. steps {
  80. withAWS(credentials:'S3_CI_BUILDS_AWS_KEYS', region:"${S3_REGION_BUILD_ARTEFACTS}") {
  81. s3Upload(file:'build.tar.gz', bucket:"${S3_BUCKET_BUILD_ARTEFACTS}", path:"${JOB_NAME}/${BUILD_NUMBER}.tar.gz")
  82. // The deployment process uses this file to figure out the latest build
  83. s3Upload(file:'build_number.txt', bucket:"${S3_BUCKET_BUILD_ARTEFACTS}", path:"${JOB_NAME}/latest")
  84. }
  85. }
  86. }
  87. }
  88. post {
  89. failure {
  90. mail(from: "${EMAIL_ALERT_FROM}",
  91. to: "${EMAIL_ALERT_TO}",
  92. subject: "Jenkins build failed: ${JOB_NAME}:${BUILD_NUMBER}",
  93. body: "Build: ${BUILD_URL}")
  94. }
  95. }
  96. // The options directive is for configuration that applies to the whole job.
  97. options {
  98. // Only build one at a time
  99. disableConcurrentBuilds()
  100. // we'd like to make sure remove old builds, so we don't fill up our storage!
  101. buildDiscarder(logRotator(numToKeepStr:'50'))
  102. // And we'd really like to be sure that this build doesn't hang forever, so let's time it out after:
  103. timeout(time: 30, unit: 'MINUTES')
  104. }
  105. }