Jenkinsfile 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. String cron_string = BRANCH_NAME == "master" ? "@daily" : ""
  2. pipeline {
  3. agent any
  4. environment {
  5. HOME = "/tmp"
  6. GIT_PROJECT = "web-sharelatex-internal"
  7. JENKINS_WORKFLOW = "web-sharelatex-internal"
  8. TARGET_URL = "${env.JENKINS_URL}blue/organizations/jenkins/${JENKINS_WORKFLOW}/detail/$BRANCH_NAME/$BUILD_NUMBER/pipeline"
  9. GIT_API_URL = "https://api.github.com/repos/sharelatex/${GIT_PROJECT}/statuses/$GIT_COMMIT"
  10. }
  11. triggers {
  12. pollSCM('* * * * *')
  13. cron(cron_string)
  14. }
  15. stages {
  16. stage('Pre') {
  17. steps {
  18. withCredentials([usernamePassword(credentialsId: 'GITHUB_INTEGRATION', usernameVariable: 'GH_AUTH_USERNAME', passwordVariable: 'GH_AUTH_PASSWORD')]) {
  19. sh "curl $GIT_API_URL \
  20. --data '{ \
  21. \"state\" : \"pending\", \
  22. \"target_url\": \"$TARGET_URL\", \
  23. \"description\": \"Your build is underway\", \
  24. \"context\": \"ci/jenkins\" }' \
  25. -u $GH_AUTH_USERNAME:$GH_AUTH_PASSWORD"
  26. }
  27. }
  28. }
  29. stage('Install modules') {
  30. steps {
  31. sshagent (credentials: ['GIT_DEPLOY_KEY']) {
  32. sh 'bin/install_modules'
  33. }
  34. }
  35. }
  36. stage('Install') {
  37. agent {
  38. docker {
  39. image 'node:6.9.5'
  40. args "-v /var/lib/jenkins/.npm:/tmp/.npm"
  41. reuseNode true
  42. }
  43. }
  44. steps {
  45. sh 'git config --global core.logallrefupdates false'
  46. sh 'rm -rf node_modules/'
  47. sh 'npm install --quiet'
  48. sh 'npm rebuild'
  49. // It's too easy to end up shrinkwrapping to an outdated version of translations.
  50. // Ensure translations are always latest, regardless of shrinkwrap
  51. sh 'npm install git+https://github.com/sharelatex/translations-sharelatex.git#master'
  52. }
  53. }
  54. stage('Compile') {
  55. agent {
  56. docker {
  57. image 'node:6.9.5'
  58. reuseNode true
  59. }
  60. }
  61. steps {
  62. sh 'make clean compile_full'
  63. // replace the build number placeholder for sentry
  64. sh 'node_modules/.bin/grunt version'
  65. }
  66. }
  67. stage('Lint') {
  68. agent {
  69. docker {
  70. image 'node:6.9.5'
  71. reuseNode true
  72. }
  73. }
  74. steps {
  75. sh 'make --no-print-directory lint'
  76. }
  77. }
  78. stage('Test and Minify') {
  79. parallel {
  80. stage('Unit Test') {
  81. agent {
  82. docker {
  83. image 'node:6.9.5'
  84. reuseNode true
  85. }
  86. }
  87. steps {
  88. sh 'make --no-print-directory test_unit MOCHA_ARGS="--reporter tap"'
  89. }
  90. }
  91. stage('Acceptance Test') {
  92. steps {
  93. // Spawns its own docker containers
  94. sh 'make --no-print-directory test_acceptance MOCHA_ARGS="--reporter tap"'
  95. }
  96. }
  97. stage('Minify') {
  98. agent {
  99. docker {
  100. image 'node:6.9.5'
  101. reuseNode true
  102. }
  103. }
  104. steps {
  105. sh 'WEBPACK_ENV=production make minify'
  106. }
  107. }
  108. }
  109. }
  110. stage('Frontend Unit Test') {
  111. steps {
  112. // Spawns its own docker containers
  113. sh 'make --no-print-directory test_frontend'
  114. }
  115. }
  116. stage('Package') {
  117. steps {
  118. sh 'rm -rf ./node_modules/grunt*'
  119. sh 'echo ${BUILD_NUMBER} > build_number.txt'
  120. sh 'touch build.tar.gz' // Avoid tar warning about files changing during read
  121. sh 'tar -czf build.tar.gz --exclude=build.tar.gz --exclude-vcs .'
  122. }
  123. }
  124. stage('Publish') {
  125. steps {
  126. withAWS(credentials:'S3_CI_BUILDS_AWS_KEYS', region:"${S3_REGION_BUILD_ARTEFACTS}") {
  127. s3Upload(file:'build.tar.gz', bucket:"${S3_BUCKET_BUILD_ARTEFACTS}", path:"${JOB_NAME}/${BUILD_NUMBER}.tar.gz")
  128. // The deployment process uses this file to figure out the latest build
  129. s3Upload(file:'build_number.txt', bucket:"${S3_BUCKET_BUILD_ARTEFACTS}", path:"${JOB_NAME}/latest")
  130. }
  131. }
  132. }
  133. stage('Sync OSS') {
  134. when {
  135. branch 'master'
  136. }
  137. steps {
  138. sshagent (credentials: ['GIT_DEPLOY_KEY']) {
  139. sh 'git push git@github.com:sharelatex/web-sharelatex.git HEAD:master'
  140. }
  141. }
  142. }
  143. }
  144. post {
  145. always {
  146. sh 'make clean_ci'
  147. }
  148. success {
  149. withCredentials([usernamePassword(credentialsId: 'GITHUB_INTEGRATION', usernameVariable: 'GH_AUTH_USERNAME', passwordVariable: 'GH_AUTH_PASSWORD')]) {
  150. sh "curl $GIT_API_URL \
  151. --data '{ \
  152. \"state\" : \"success\", \
  153. \"target_url\": \"$TARGET_URL\", \
  154. \"description\": \"Your build succeeded!\", \
  155. \"context\": \"ci/jenkins\" }' \
  156. -u $GH_AUTH_USERNAME:$GH_AUTH_PASSWORD"
  157. }
  158. }
  159. failure {
  160. mail(from: "${EMAIL_ALERT_FROM}",
  161. to: "${EMAIL_ALERT_TO}",
  162. subject: "Jenkins build failed: ${JOB_NAME}:${BUILD_NUMBER}",
  163. body: "Build: ${BUILD_URL}")
  164. withCredentials([usernamePassword(credentialsId: 'GITHUB_INTEGRATION', usernameVariable: 'GH_AUTH_USERNAME', passwordVariable: 'GH_AUTH_PASSWORD')]) {
  165. sh "curl $GIT_API_URL \
  166. --data '{ \
  167. \"state\" : \"failure\", \
  168. \"target_url\": \"$TARGET_URL\", \
  169. \"description\": \"Your build failed\", \
  170. \"context\": \"ci/jenkins\" }' \
  171. -u $GH_AUTH_USERNAME:$GH_AUTH_PASSWORD"
  172. }
  173. }
  174. }
  175. // The options directive is for configuration that applies to the whole job.
  176. options {
  177. // Only build one at a time
  178. disableConcurrentBuilds()
  179. // we'd like to make sure remove old builds, so we don't fill up our storage!
  180. buildDiscarder(logRotator(numToKeepStr:'50'))
  181. // And we'd really like to be sure that this build doesn't hang forever, so let's time it out after:
  182. timeout(time: 30, unit: 'MINUTES')
  183. }
  184. }