Jenkinsfile 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. String cron_string = BRANCH_NAME == "master" ? "@daily" : ""
  2. pipeline {
  3. agent any
  4. triggers {
  5. pollSCM('* * * * *')
  6. cron(cron_string)
  7. }
  8. stages {
  9. stage('Install') {
  10. agent {
  11. docker {
  12. image 'node:6.9.5'
  13. args "-v /var/lib/jenkins/.npm:/tmp/.npm -e HOME=/tmp"
  14. reuseNode true
  15. }
  16. }
  17. steps {
  18. // we need to disable logallrefupdates, else git clones
  19. // during the npm install will require git to lookup the
  20. // user id which does not exist in the container's
  21. // /etc/passwd file, causing the clone to fail.
  22. sh 'git config --global core.logallrefupdates false'
  23. sh 'rm -rf node_modules'
  24. sh 'npm install && npm rebuild'
  25. }
  26. }
  27. stage('Compile') {
  28. agent {
  29. docker {
  30. image 'node:6.9.5'
  31. reuseNode true
  32. }
  33. }
  34. steps {
  35. sh 'npm run compile:all'
  36. }
  37. }
  38. stage('Unit Tests') {
  39. steps {
  40. sh 'DOCKER_COMPOSE_FLAGS="-f docker-compose.ci.yml" make test_unit'
  41. }
  42. }
  43. stage('Acceptance Tests') {
  44. steps {
  45. sh 'DOCKER_COMPOSE_FLAGS="-f docker-compose.ci.yml" make test_acceptance'
  46. }
  47. }
  48. stage('Package and publish build') {
  49. steps {
  50. sh 'echo ${BUILD_NUMBER} > build_number.txt'
  51. sh 'touch build.tar.gz' // Avoid tar warning about files changing during read
  52. sh 'tar -czf build.tar.gz --exclude=build.tar.gz --exclude-vcs .'
  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. }
  56. }
  57. }
  58. stage('Publish build number') {
  59. steps {
  60. sh 'echo ${BRANCH_NAME}-${BUILD_NUMBER} > build_number.txt'
  61. withAWS(credentials:'S3_CI_BUILDS_AWS_KEYS', region:"${S3_REGION_BUILD_ARTEFACTS}") {
  62. // The deployment process uses this file to figure out the latest build
  63. s3Upload(file:'build_number.txt', bucket:"${S3_BUCKET_BUILD_ARTEFACTS}", path:"${JOB_NAME}/latest")
  64. }
  65. }
  66. }
  67. }
  68. post {
  69. always {
  70. sh 'DOCKER_COMPOSE_FLAGS="-f docker-compose.ci.yml" make test_clean'
  71. }
  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. }