Jenkinsfile 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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('Copy external pages') {
  30. steps {
  31. sh 'bin/copy_external_pages'
  32. }
  33. }
  34. stage('Install') {
  35. agent {
  36. docker {
  37. image 'node:6.9.5'
  38. args "-v /var/lib/jenkins/.npm:/tmp/.npm"
  39. reuseNode true
  40. }
  41. }
  42. steps {
  43. sh 'git config --global core.logallrefupdates false'
  44. sh 'rm -rf node_modules/'
  45. sh 'npm install --quiet'
  46. sh 'npm rebuild'
  47. // It's too easy to end up shrinkwrapping to an outdated version of translations.
  48. // Ensure translations are always latest, regardless of shrinkwrap
  49. sh 'npm install git+https://github.com/sharelatex/translations-sharelatex.git#master'
  50. }
  51. }
  52. stage('Compile') {
  53. agent {
  54. docker {
  55. image 'node:6.9.5'
  56. reuseNode true
  57. }
  58. }
  59. steps {
  60. sh 'make clean compile_full'
  61. // replace the build number placeholder for sentry
  62. sh 'node_modules/.bin/grunt version'
  63. }
  64. }
  65. stage('Lint') {
  66. agent {
  67. docker {
  68. image 'node:6.9.5'
  69. reuseNode true
  70. }
  71. }
  72. steps {
  73. sh 'make --no-print-directory lint'
  74. }
  75. }
  76. stage('Test and Minify') {
  77. parallel {
  78. stage('Unit Test') {
  79. agent {
  80. docker {
  81. image 'node:6.9.5'
  82. reuseNode true
  83. }
  84. }
  85. steps {
  86. sh 'make --no-print-directory test_unit MOCHA_ARGS="--reporter tap"'
  87. }
  88. }
  89. stage('Acceptance Test') {
  90. steps {
  91. // Spawns its own docker containers
  92. sh 'make --no-print-directory test_acceptance MOCHA_ARGS="--reporter tap"'
  93. }
  94. }
  95. stage('Minify') {
  96. agent {
  97. docker {
  98. image 'node:6.9.5'
  99. reuseNode true
  100. }
  101. }
  102. steps {
  103. sh 'WEBPACK_ENV=production make minify'
  104. }
  105. }
  106. }
  107. }
  108. stage('Frontend Unit Test') {
  109. steps {
  110. // Spawns its own docker containers
  111. sh 'make --no-print-directory test_frontend'
  112. }
  113. }
  114. stage('Package') {
  115. steps {
  116. sh 'rm -rf ./node_modules/grunt*'
  117. sh 'echo ${BUILD_NUMBER} > build_number.txt'
  118. sh 'touch build.tar.gz' // Avoid tar warning about files changing during read
  119. sh 'tar -czf build.tar.gz --exclude=build.tar.gz --exclude-vcs .'
  120. }
  121. }
  122. stage('Publish') {
  123. steps {
  124. withAWS(credentials:'S3_CI_BUILDS_AWS_KEYS', region:"${S3_REGION_BUILD_ARTEFACTS}") {
  125. s3Upload(file:'build.tar.gz', bucket:"${S3_BUCKET_BUILD_ARTEFACTS}", path:"${JOB_NAME}/${BUILD_NUMBER}.tar.gz")
  126. // The deployment process uses this file to figure out the latest build
  127. s3Upload(file:'build_number.txt', bucket:"${S3_BUCKET_BUILD_ARTEFACTS}", path:"${JOB_NAME}/latest")
  128. }
  129. }
  130. }
  131. stage('Sync OSS') {
  132. when {
  133. branch 'master'
  134. }
  135. agent {
  136. docker {
  137. image 'sharelatex/copybara'
  138. args "-u 0:0 -v /tmp/copybara:/root/copybara/cache"
  139. }
  140. }
  141. steps {
  142. sshagent (credentials: ['GIT_DEPLOY_KEY']) {
  143. sh 'git config --global user.name Copybot'
  144. sh 'git config --global user.email copybot@overleaf.com'
  145. sh 'mkdir -p /root/.ssh'
  146. sh 'ssh-keyscan github.com >> /root/.ssh/known_hosts'
  147. sh 'COPYBARA_CONFIG=./copybara/copy.bara.sky copybara --git-committer-email=copybot@overleaf.com --git-committer-name=Copybot || true'
  148. }
  149. }
  150. }
  151. }
  152. post {
  153. always {
  154. sh 'make clean_ci'
  155. }
  156. success {
  157. withCredentials([usernamePassword(credentialsId: 'GITHUB_INTEGRATION', usernameVariable: 'GH_AUTH_USERNAME', passwordVariable: 'GH_AUTH_PASSWORD')]) {
  158. sh "curl $GIT_API_URL \
  159. --data '{ \
  160. \"state\" : \"success\", \
  161. \"target_url\": \"$TARGET_URL\", \
  162. \"description\": \"Your build succeeded!\", \
  163. \"context\": \"ci/jenkins\" }' \
  164. -u $GH_AUTH_USERNAME:$GH_AUTH_PASSWORD"
  165. }
  166. }
  167. failure {
  168. mail(from: "${EMAIL_ALERT_FROM}",
  169. to: "${EMAIL_ALERT_TO}",
  170. subject: "Jenkins build failed: ${JOB_NAME}:${BUILD_NUMBER}",
  171. body: "Build: ${BUILD_URL}")
  172. withCredentials([usernamePassword(credentialsId: 'GITHUB_INTEGRATION', usernameVariable: 'GH_AUTH_USERNAME', passwordVariable: 'GH_AUTH_PASSWORD')]) {
  173. sh "curl $GIT_API_URL \
  174. --data '{ \
  175. \"state\" : \"failure\", \
  176. \"target_url\": \"$TARGET_URL\", \
  177. \"description\": \"Your build failed\", \
  178. \"context\": \"ci/jenkins\" }' \
  179. -u $GH_AUTH_USERNAME:$GH_AUTH_PASSWORD"
  180. }
  181. }
  182. }
  183. // The options directive is for configuration that applies to the whole job.
  184. options {
  185. // Only build one at a time
  186. disableConcurrentBuilds()
  187. // we'd like to make sure remove old builds, so we don't fill up our storage!
  188. buildDiscarder(logRotator(numToKeepStr:'50'))
  189. // And we'd really like to be sure that this build doesn't hang forever, so let's time it out after:
  190. timeout(time: 30, unit: 'MINUTES')
  191. }
  192. }