Jenkinsfile 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. // Autogenerated by build scripts. Do not edit.
  2. pipeline {
  3. agent {
  4. node {
  5. label 'jenkins-agent-web'
  6. customWorkspace '/workspace'
  7. }
  8. }
  9. options {
  10. timestamps()
  11. timeout(time: 15, unit: 'MINUTES')
  12. }
  13. environment {
  14. BRANCH_NAME = "${env.CHANGE_BRANCH ? env.CHANGE_BRANCH : env.BRANCH_NAME}"
  15. JENKINS_BUILD_NUMBER = "${BUILD_NUMBER}"
  16. DOCKER_COMPOSE_FLAGS = '-f docker-compose.ci.yml'
  17. }
  18. stages {
  19. stage('Set Build Variables') {
  20. steps {
  21. script {
  22. def relevantCommitHash
  23. if (env.CHANGE_BRANCH) {
  24. def commitExistsOnRemote = sh(script: "git branch --remotes --contains ${GIT_COMMIT}", returnStdout: true).trim()
  25. if (commitExistsOnRemote) {
  26. echo "PR build detected, but commit exists on remote. Using ${GIT_COMMIT}"
  27. relevantCommitHash = "${GIT_COMMIT}"
  28. } else {
  29. def parentCommits = sh(script: 'git rev-parse HEAD^@', returnStdout: true).trim().split('\n')
  30. if (parentCommits.size() >= 2) {
  31. echo "PR build detected. Jenkins checked out a merge commit: ${GIT_COMMIT} (parents: ${parentCommits.join(', ')})"
  32. relevantCommitHash = parentCommits[0]
  33. echo "Using first parent (branch commit): ${relevantCommitHash}"
  34. } else {
  35. echo "WARN: PR build detected, but ${GIT_COMMIT} is neither a merge commit, nor does it exist on the remote."
  36. relevantCommitHash = "${GIT_COMMIT}"
  37. }
  38. }
  39. } else {
  40. echo "Branch build detected. Using commit: ${GIT_COMMIT}"
  41. relevantCommitHash = "${GIT_COMMIT}"
  42. }
  43. env.COMMIT_SHA = relevantCommitHash
  44. env.SHORT_SHA = relevantCommitHash.take(7)
  45. env.BUILD_NUMBER = "${env.SHORT_SHA}_${env.JENKINS_BUILD_NUMBER}"
  46. }
  47. }
  48. }
  49. stage('Stage 1') {
  50. parallel {
  51. stage('Build') {
  52. steps {
  53. dir('services/clsi') {
  54. retry(count: 3) {
  55. sh 'make build'
  56. }
  57. }
  58. }
  59. }
  60. stage('Pull TL2017') {
  61. steps {
  62. // Remove after new worker VM image is live.
  63. sh 'docker pull us-east1-docker.pkg.dev/overleaf-ops/ol-docker/texlive-full:2017.1'
  64. }
  65. }
  66. stage('Create reports folder') {
  67. steps {
  68. sh 'mkdir services/clsi/reports'
  69. }
  70. }
  71. }
  72. }
  73. stage('Stage 2') {
  74. parallel {
  75. stage('Push Branch Image') {
  76. steps {
  77. dir('services/clsi') {
  78. sh 'make push_branch'
  79. }
  80. }
  81. }
  82. stage('Shellcheck') {
  83. steps {
  84. dir('services/clsi') {
  85. sh 'make shellcheck'
  86. }
  87. }
  88. }
  89. stage('Lint') {
  90. steps {
  91. dir('services/clsi') {
  92. sh 'make lint_ci'
  93. }
  94. }
  95. post {
  96. always {
  97. recordIssues checksAnnotationScope: 'ALL', enabledForFailure: true, failOnError: true, id: 'clsi-eslint', name: 'clsi eslint', qualityGates: [[integerThreshold: 1, threshold: 1.0, type: 'TOTAL']], sourceCodeRetention: 'LAST_BUILD', tools: [esLint(pattern: 'services/clsi/reports/eslint.json')]
  98. }
  99. }
  100. }
  101. stage('Format') {
  102. steps {
  103. dir('services/clsi') {
  104. sh 'make format_ci'
  105. }
  106. }
  107. }
  108. stage('Typecheck') {
  109. steps {
  110. dir('services/clsi') {
  111. sh 'make typecheck_ci'
  112. }
  113. }
  114. }
  115. stage('Test Unit') {
  116. steps {
  117. dir('services/clsi') {
  118. retry(count: 3) {
  119. sh 'make test_unit'
  120. }
  121. }
  122. }
  123. }
  124. stage('Test Acceptance') {
  125. environment {
  126. COMPOSE_PROJECT_NAME_TEST_ACCEPTANCE = "test_acceptance"
  127. }
  128. steps {
  129. dir('services/clsi') {
  130. retry(count: 3) {
  131. sh 'make test_acceptance'
  132. }
  133. }
  134. }
  135. }
  136. }
  137. }
  138. stage('Push Production') {
  139. steps {
  140. dir('services/clsi') {
  141. sh 'make push'
  142. }
  143. }
  144. }
  145. }
  146. post {
  147. always {
  148. junit checksName: 'clsi test results', testResults: 'services/clsi/reports/junit-*.xml'
  149. }
  150. cleanup {
  151. dir('services/clsi') {
  152. sh 'make clean'
  153. }
  154. sh 'make clean_jenkins -j10'
  155. }
  156. }
  157. }