Jenkinsfile 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. }
  17. stages {
  18. stage('Set Build Variables') {
  19. steps {
  20. script {
  21. def relevantCommitHash
  22. if (env.CHANGE_BRANCH) {
  23. def commitExistsOnRemote = sh(script: "git branch --remotes --contains ${GIT_COMMIT}", returnStdout: true).trim()
  24. if (commitExistsOnRemote) {
  25. echo "PR build detected, but commit exists on remote. Using ${GIT_COMMIT}"
  26. relevantCommitHash = "${GIT_COMMIT}"
  27. } else {
  28. def parentCommits = sh(script: 'git rev-parse HEAD^@', returnStdout: true).trim().split('\n')
  29. if (parentCommits.size() >= 2) {
  30. echo "PR build detected. Jenkins checked out a merge commit: ${GIT_COMMIT} (parents: ${parentCommits.join(', ')})"
  31. relevantCommitHash = parentCommits[0]
  32. echo "Using first parent (branch commit): ${relevantCommitHash}"
  33. } else {
  34. echo "WARN: PR build detected, but ${GIT_COMMIT} is neither a merge commit, nor does it exist on the remote."
  35. relevantCommitHash = "${GIT_COMMIT}"
  36. }
  37. }
  38. } else {
  39. echo "Branch build detected. Using commit: ${GIT_COMMIT}"
  40. relevantCommitHash = "${GIT_COMMIT}"
  41. }
  42. env.COMMIT_SHA = relevantCommitHash
  43. env.SHORT_SHA = relevantCommitHash.take(7)
  44. env.BUILD_NUMBER = "${env.SHORT_SHA}_${env.JENKINS_BUILD_NUMBER}"
  45. }
  46. }
  47. }
  48. stage('Stage 1') {
  49. parallel {
  50. stage('Install monorepo') {
  51. steps {
  52. retry(count: 3) {
  53. sh 'make monorepo_setup'
  54. }
  55. }
  56. }
  57. stage('Create reports folder') {
  58. steps {
  59. sh 'mkdir libraries/redis-wrapper/reports'
  60. }
  61. }
  62. }
  63. }
  64. stage('Stage 2') {
  65. parallel {
  66. stage('Lint') {
  67. steps {
  68. sh 'bin/run -w /overleaf/libraries/redis-wrapper monorepo npm run lint -- --format json --output-file reports/eslint.json'
  69. }
  70. post {
  71. always {
  72. sh """
  73. sed -i 's_"filePath":"/overleaf_"filePath":"/workspace_g' libraries/redis-wrapper/reports/eslint.json
  74. """
  75. recordIssues checksAnnotationScope: 'ALL', enabledForFailure: true, failOnError: true, id: 'redis-wrapper-eslint', name: 'redis-wrapper eslint', qualityGates: [[integerThreshold: 1, threshold: 1.0, type: 'TOTAL']], sourceCodeRetention: 'LAST_BUILD', tools: [esLint(pattern: 'libraries/redis-wrapper/reports/eslint.json')]
  76. }
  77. }
  78. }
  79. stage('Format') {
  80. steps {
  81. sh 'bin/run -w /overleaf/libraries/redis-wrapper monorepo npm run format'
  82. }
  83. }
  84. stage('Typecheck') {
  85. steps {
  86. sh 'bin/run -w /overleaf/libraries/redis-wrapper monorepo npm run types:check'
  87. }
  88. }
  89. stage('Test') {
  90. steps {
  91. retry(count: 3) {
  92. sh 'bin/run -w /overleaf/libraries/redis-wrapper monorepo npm run test:ci'
  93. }
  94. }
  95. }
  96. }
  97. }
  98. }
  99. post {
  100. always {
  101. junit checksName: 'redis-wrapper test results', testResults: 'libraries/redis-wrapper/reports/junit-*.xml'
  102. }
  103. failure {
  104. script {
  105. if (env.BRANCH_NAME == 'main') {
  106. node('built-in') {
  107. sh '/usr/local/bin/open-gh-failure-issue --project="🚉 Platform"'
  108. }
  109. }
  110. }
  111. }
  112. cleanup {
  113. sh 'rm -rf libraries/redis-wrapper/reports'
  114. sh 'make clean_jenkins -j10'
  115. }
  116. }
  117. }