Jenkinsfile 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. pipeline {
  2. agent {
  3. docker {
  4. image 'node:4.2.1'
  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. }
  22. }
  23. stage('Install') {
  24. steps {
  25. sh 'rm -fr node_modules'
  26. sh 'npm install'
  27. sh 'npm rebuild'
  28. sh 'npm install --quiet grunt-cli'
  29. }
  30. }
  31. stage('Compile') {
  32. steps {
  33. sh 'node_modules/.bin/grunt compile:app'
  34. }
  35. }
  36. stage('Test') {
  37. steps {
  38. sh 'node_modules/.bin/grunt test:unit'
  39. }
  40. }
  41. stage('Package') {
  42. steps {
  43. sh 'echo ${BUILD_NUMBER} > build_number.txt'
  44. sh 'touch build.tar.gz' // Avoid tar warning about files changing during read
  45. sh 'tar -czf build.tar.gz --exclude=build.tar.gz --exclude-vcs .'
  46. }
  47. }
  48. stage('Publish') {
  49. steps {
  50. withAWS(credentials:'S3_CI_BUILDS_AWS_KEYS', region:"${S3_REGION_BUILD_ARTEFACTS}") {
  51. s3Upload(file:'build.tar.gz', bucket:"${S3_BUCKET_BUILD_ARTEFACTS}", path:"${JOB_NAME}/${BUILD_NUMBER}.tar.gz")
  52. // The deployment process uses this file to figure out the latest build
  53. s3Upload(file:'build_number.txt', bucket:"${S3_BUCKET_BUILD_ARTEFACTS}", path:"${JOB_NAME}/latest")
  54. }
  55. }
  56. }
  57. }
  58. post {
  59. failure {
  60. when {
  61. branch 'master'
  62. }
  63. mail(from: "${EMAIL_ALERT_FROM}",
  64. to: "${EMAIL_ALERT_TO}",
  65. subject: "Jenkins build failed: ${JOB_NAME}:${BUILD_NUMBER}",
  66. body: "Build: ${BUILD_URL}")
  67. }
  68. }
  69. // The options directive is for configuration that applies to the whole job.
  70. options {
  71. // we'd like to make sure remove old builds, so we don't fill up our storage!
  72. buildDiscarder(logRotator(numToKeepStr:'50'))
  73. // And we'd really like to be sure that this build doesn't hang forever, so let's time it out after:
  74. timeout(time: 30, unit: 'MINUTES')
  75. }
  76. }