Jenkinsfile 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. pipeline {
  2. agent {
  3. node {
  4. // Select a VM with the given tabel.
  5. label 'jenkins-agent-web'
  6. // Use the monorepo checkout in /workspace.
  7. customWorkspace '/workspace'
  8. }
  9. }
  10. options {
  11. // Print timestamp next to each log line.
  12. timestamps()
  13. timeout(time: 15, unit: 'MINUTES')
  14. }
  15. environment {
  16. IMAGE_NAME = 'web'
  17. PROJECT_NAME = 'web'
  18. IMAGE_REPO = 'us-east1-docker.pkg.dev/overleaf-ops/ol-docker/web'
  19. AR_REPO_LOCATION = 'us-east1'
  20. AR_URL = 'us-east1-docker.pkg.dev/overleaf-ops/ol-docker'
  21. DOCKER_COMPOSE_FLAGS = '-f docker-compose.ci.yml'
  22. BRANCH_NAME = "${env.CHANGE_BRANCH ? env.CHANGE_BRANCH : env.BRANCH_NAME}"
  23. JENKINS_BUILD_NUMBER = "${BUILD_NUMBER}" // preserve original BUILD_NUMBER
  24. CDN_STAG = "gs://ol-stag-web-assets-1"
  25. CDN_PROD = "gs://mgcp-1117973-ol-prod-web-assets-1"
  26. }
  27. stages {
  28. stage('Set Build Variables') {
  29. steps {
  30. script {
  31. def relevantCommitHash
  32. if (env.CHANGE_BRANCH) {
  33. def commitExistsOnRemote = sh(script: "git branch --remotes --contains ${GIT_COMMIT}", returnStdout: true).trim()
  34. if (commitExistsOnRemote) {
  35. echo "PR build detected, but commit exists on remote. Using ${GIT_COMMIT}"
  36. relevantCommitHash = "${GIT_COMMIT}"
  37. } else {
  38. def parentCommits = sh(script: 'git rev-parse HEAD^@', returnStdout: true).trim().split('\n')
  39. if (parentCommits.size() >= 2) {
  40. echo "PR build detected. Jenkins checked out a merge commit: ${GIT_COMMIT} (parents: ${parentCommits.join(', ')})"
  41. relevantCommitHash = parentCommits[0]
  42. echo "Using first parent (branch commit): ${relevantCommitHash}"
  43. } else {
  44. echo "WARN: PR build detected, but ${GIT_COMMIT} is neither a merge commit, nor does it exist on the remote."
  45. relevantCommitHash = "${GIT_COMMIT}"
  46. }
  47. }
  48. } else {
  49. echo "Branch build detected. Using commit: ${GIT_COMMIT}"
  50. relevantCommitHash = "${GIT_COMMIT}"
  51. }
  52. env.COMMIT_SHA = relevantCommitHash
  53. env.SHORT_SHA = relevantCommitHash.take(7)
  54. env.BUILD_NUMBER = "${env.SHORT_SHA}_${env.JENKINS_BUILD_NUMBER}"
  55. }
  56. }
  57. }
  58. stage('Stage 1') {
  59. parallel {
  60. stage('Prefetch Tests Images') {
  61. steps {
  62. dir('services/web') {
  63. sh 'docker compose -f docker-compose.ci.yml pull --quiet test_frontend_ct mongo redis_test ldap saml'
  64. }
  65. }
  66. }
  67. stage('Build') {
  68. steps {
  69. dir('services/web') {
  70. sh 'bin/copy_external_pages'
  71. retry(count: 3) {
  72. sh 'make build_deps'
  73. }
  74. retry(count: 3) {
  75. sh 'make build_dev'
  76. }
  77. sh 'make build_test_frontend_ct'
  78. }
  79. }
  80. }
  81. }
  82. }
  83. stage('Stage 2') {
  84. parallel {
  85. stage('Push Deps') {
  86. steps {
  87. dir('services/web') {
  88. sh 'make push_branch'
  89. }
  90. }
  91. }
  92. stage('Format') {
  93. steps {
  94. dir('services/web') {
  95. sh 'make format_in_docker'
  96. }
  97. }
  98. }
  99. stage('Lint') {
  100. steps {
  101. dir('services/web') {
  102. sh 'make lint_in_docker'
  103. }
  104. }
  105. post {
  106. always {
  107. recordIssues checksAnnotationScope: 'ALL', enabledForFailure: true, failOnError: true, id: 'web-eslint', name: 'Web eslint', qualityGates: [[integerThreshold: 1, threshold: 1.0, type: 'TOTAL']], sourceCodeRetention: 'LAST_BUILD', tools: [esLint(pattern: 'services/web/data/reports/eslint.json')]
  108. recordIssues checksAnnotationScope: 'ALL', enabledForFailure: true, failOnError: true, id: 'web-stylelint', name: 'Web stylelint', qualityGates: [[integerThreshold: 1, threshold: 1.0, type: 'TOTAL']], sourceCodeRetention: 'LAST_BUILD', tools: [styleLint(pattern: 'services/web/data/reports/stylelint.json')]
  109. }
  110. }
  111. }
  112. stage('Shellcheck') {
  113. steps {
  114. dir('services/web') {
  115. sh 'make shellcheck'
  116. }
  117. }
  118. }
  119. stage('Acceptance SaaS') {
  120. steps {
  121. dir('services/web') {
  122. retry(count: 3) {
  123. sh 'make test_acceptance_app_saas'
  124. }
  125. }
  126. }
  127. }
  128. stage('Acceptance Server CE') {
  129. steps {
  130. dir('services/web') {
  131. retry(count: 3) {
  132. sh "make test_acceptance_app_server_ce"
  133. }
  134. }
  135. }
  136. }
  137. stage('Acceptance Server Pro') {
  138. steps {
  139. dir('services/web') {
  140. retry(count: 3) {
  141. sh "make test_acceptance_app_server_pro"
  142. }
  143. }
  144. }
  145. }
  146. stage('test_acceptance_modules_merged_saas_1') {
  147. steps {
  148. dir('services/web') {
  149. retry(count: 3) {
  150. sh "make test_acceptance_modules_merged_saas_1"
  151. }
  152. }
  153. }
  154. }
  155. stage('test_acceptance_modules_merged_saas_2') {
  156. steps {
  157. dir('services/web') {
  158. retry(count: 3) {
  159. sh "make test_acceptance_modules_merged_saas_2"
  160. }
  161. }
  162. }
  163. }
  164. stage('test_acceptance_modules_merged_saas_3') {
  165. steps {
  166. dir('services/web') {
  167. retry(count: 3) {
  168. sh "make test_acceptance_modules_merged_saas_3"
  169. }
  170. }
  171. }
  172. }
  173. stage('test_acceptance_modules_merged_saas_4') {
  174. steps {
  175. dir('services/web') {
  176. retry(count: 3) {
  177. sh "make test_acceptance_modules_merged_saas_4"
  178. }
  179. }
  180. }
  181. }
  182. stage('test_acceptance_modules_merged_server_ce') {
  183. steps {
  184. dir('services/web') {
  185. retry(count: 3) {
  186. sh "make test_acceptance_modules_merged_server_ce"
  187. }
  188. }
  189. }
  190. }
  191. stage('test_acceptance_modules_merged_server_pro') {
  192. steps {
  193. dir('services/web') {
  194. retry(count: 3) {
  195. sh "make test_acceptance_modules_merged_server_pro"
  196. }
  197. }
  198. }
  199. }
  200. stage('test_frontend') {
  201. steps {
  202. dir('services/web') {
  203. retry(count: 3) {
  204. sh "make test_frontend"
  205. }
  206. }
  207. }
  208. }
  209. stage('test_writefull') {
  210. steps {
  211. dir('services/web') {
  212. retry(count: 3) {
  213. sh "make test_writefull"
  214. }
  215. }
  216. }
  217. }
  218. stage('test_frontend_ct_core_other') {
  219. environment {
  220. CYPRESS_INTERNAL_BROWSER_CONNECT_TIMEOUT = '120000'
  221. }
  222. steps {
  223. dir('services/web') {
  224. retry(count: 3) {
  225. sh "make test_frontend_ct_core_other"
  226. }
  227. }
  228. }
  229. }
  230. stage('test_frontend_ct_core_features') {
  231. environment {
  232. CYPRESS_INTERNAL_BROWSER_CONNECT_TIMEOUT = '120000'
  233. }
  234. steps {
  235. dir('services/web') {
  236. retry(count: 3) {
  237. sh "make test_frontend_ct_core_features"
  238. }
  239. }
  240. }
  241. }
  242. stage('test_frontend_ct_modules') {
  243. environment {
  244. CYPRESS_INTERNAL_BROWSER_CONNECT_TIMEOUT = '120000'
  245. }
  246. steps {
  247. dir('services/web') {
  248. retry(count: 3) {
  249. sh "make test_frontend_ct_modules"
  250. }
  251. }
  252. }
  253. }
  254. stage('test_frontend_ct_editor_visual') {
  255. steps {
  256. dir('services/web') {
  257. retry(count: 3) {
  258. sh "make test_frontend_ct_editor_visual"
  259. }
  260. }
  261. }
  262. }
  263. stage('test_frontend_ct_editor_other') {
  264. steps {
  265. dir('services/web') {
  266. retry(count: 3) {
  267. sh "make test_frontend_ct_editor_other"
  268. }
  269. }
  270. }
  271. }
  272. stage('Test Unit ESM - Parallel') {
  273. steps {
  274. dir('services/web') {
  275. retry(count: 3) {
  276. sh "make test_unit_esm_parallel"
  277. }
  278. }
  279. }
  280. }
  281. stage('Test Unit ESM - Sequential') {
  282. steps {
  283. dir('services/web') {
  284. retry(count: 3) {
  285. sh "make test_unit_esm_sequential"
  286. }
  287. }
  288. }
  289. }
  290. stage('Test Unit Mocha') {
  291. steps {
  292. dir('services/web') {
  293. retry(count: 3) {
  294. sh "make test_unit_mocha"
  295. }
  296. }
  297. }
  298. }
  299. stage('Build webpack + production + cdn upload + sentry upload') {
  300. stages {
  301. stage('Wait a bit to give tests all the CPU capacity') {
  302. steps {
  303. sh 'sleep 60'
  304. }
  305. }
  306. stage('Build Webpack') {
  307. steps {
  308. dir('services/web') {
  309. sh 'make build_webpack'
  310. }
  311. }
  312. }
  313. stage('Build Pug') {
  314. steps {
  315. dir('services/web') {
  316. sh 'make build_pug'
  317. }
  318. }
  319. }
  320. stage('CDN Upload Image') {
  321. steps {
  322. dir('services/web') {
  323. sh 'make tar'
  324. retry(count: 3) {
  325. sh 'bin/cdn_upload'
  326. }
  327. }
  328. }
  329. }
  330. stage('Build Production') {
  331. steps {
  332. dir('services/web') {
  333. sh 'make build'
  334. }
  335. }
  336. }
  337. stage('Sentry Upload') {
  338. steps {
  339. dir('services/web') {
  340. sh 'gcloud secrets versions access latest --secret=web-sentryclirc > .sentryclirc'
  341. retry(count: 3) {
  342. sh 'make sentry_upload'
  343. }
  344. }
  345. }
  346. post {
  347. cleanup {
  348. dir('services/web') {
  349. sh 'rm -f .sentryclirc'
  350. }
  351. }
  352. }
  353. }
  354. stage('Push Production image early') {
  355. steps {
  356. dir('services/web') {
  357. sh 'make push_scratch'
  358. }
  359. }
  360. }
  361. }
  362. }
  363. }
  364. }
  365. stage('Push Production') {
  366. steps {
  367. dir('services/web') {
  368. sh 'make publish'
  369. }
  370. }
  371. }
  372. }
  373. post {
  374. always {
  375. junit checksName: 'Web test results', testResults: 'services/web/data/reports/junit-*.xml,services/web/data/reports/junit-*/**/*.xml'
  376. }
  377. // Ensure tear down of test containers, then run general Jenkins VM cleanup.
  378. cleanup {
  379. dir('services/web') {
  380. sh 'make clean -j10'
  381. }
  382. sh 'make clean_jenkins -j10'
  383. }
  384. }
  385. }
  386. // vim: set ft=groovy :