Jenkinsfile 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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/chat') {
  54. retry(count: 3) {
  55. sh 'make build'
  56. }
  57. }
  58. }
  59. }
  60. stage('Create reports folder') {
  61. steps {
  62. sh 'mkdir services/chat/reports'
  63. }
  64. }
  65. }
  66. }
  67. stage('Stage 2') {
  68. parallel {
  69. stage('Push Branch Image') {
  70. steps {
  71. dir('services/chat') {
  72. sh 'make push_branch'
  73. }
  74. }
  75. }
  76. stage('Shellcheck') {
  77. steps {
  78. dir('services/chat') {
  79. sh 'make shellcheck'
  80. }
  81. }
  82. }
  83. stage('Lint') {
  84. steps {
  85. dir('services/chat') {
  86. sh 'make lint_ci'
  87. }
  88. }
  89. post {
  90. always {
  91. recordIssues checksAnnotationScope: 'ALL', enabledForFailure: true, failOnError: true, id: 'chat-eslint', name: 'chat eslint', qualityGates: [[integerThreshold: 1, threshold: 1.0, type: 'TOTAL']], sourceCodeRetention: 'LAST_BUILD', tools: [esLint(pattern: 'services/chat/reports/eslint.json')]
  92. }
  93. }
  94. }
  95. stage('Format') {
  96. steps {
  97. dir('services/chat') {
  98. sh 'make format_ci'
  99. }
  100. }
  101. }
  102. stage('Typecheck') {
  103. steps {
  104. dir('services/chat') {
  105. sh 'make typecheck_ci'
  106. }
  107. }
  108. }
  109. stage('Test Unit') {
  110. steps {
  111. dir('services/chat') {
  112. retry(count: 3) {
  113. sh 'make test_unit'
  114. }
  115. }
  116. }
  117. }
  118. stage('Test Acceptance') {
  119. environment {
  120. COMPOSE_PROJECT_NAME_TEST_ACCEPTANCE = "test_acceptance"
  121. }
  122. steps {
  123. dir('services/chat') {
  124. retry(count: 3) {
  125. sh 'make test_acceptance'
  126. }
  127. }
  128. }
  129. }
  130. }
  131. }
  132. stage('Push Production') {
  133. steps {
  134. dir('services/chat') {
  135. sh 'make push'
  136. }
  137. }
  138. }
  139. }
  140. post {
  141. always {
  142. junit checksName: 'chat test results', testResults: 'services/chat/reports/junit-*.xml'
  143. }
  144. failure {
  145. script {
  146. if (env.BRANCH_NAME == 'main') {
  147. node('built-in') {
  148. sh '/usr/local/bin/open-gh-failure-issue --project="🥑 Core"'
  149. }
  150. }
  151. }
  152. }
  153. cleanup {
  154. dir('services/chat') {
  155. sh 'make clean'
  156. }
  157. sh 'make clean_jenkins -j10'
  158. }
  159. }
  160. }