You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // Jenkinsfile CI/CD Pipeline for Test Execution
  2. // Generated by BMad TEA Agent - Test Architect Module
  3. // Optimized for: Parallel Sharding, Burn-In Loop
  4. // Stack: {test_stack_type} | Framework: {test_framework}
  5. //
  6. // Variables to customize per project:
  7. // INSTALL_CMD - dependency install command (e.g., npm ci, pnpm install --frozen-lockfile)
  8. // TEST_CMD - main test command (e.g., npm run test:e2e, npm test, npx vitest)
  9. // LINT_CMD - lint command (e.g., npm run lint)
  10. // BROWSER_INSTALL - browser install command (frontend/fullstack only; omit for backend)
  11. //
  12. // Node.js version management — choose one:
  13. // Option A (recommended): Configure NodeJS Plugin in Jenkins Global Tool Configuration,
  14. // then add to pipeline: tools { nodejs 'NodeJS-24' }
  15. // Option B: Use nvm (pre-installed on agent) — this template uses nvm as the default
  16. // Option C: Use a Docker agent — agent { docker { image 'node:24' } }
  17. pipeline {
  18. agent any
  19. environment {
  20. CI = 'true'
  21. }
  22. options {
  23. timeout(time: 45, unit: 'MINUTES')
  24. disableConcurrentBuilds()
  25. }
  26. stages {
  27. stage('Checkout') {
  28. steps {
  29. checkout scm
  30. }
  31. }
  32. stage('Install') {
  33. steps {
  34. // Detect and apply Node.js version from .nvmrc (falls back to v24)
  35. // If using NodeJS Plugin instead, remove this block and add: tools { nodejs 'NodeJS-24' }
  36. sh '''
  37. export NVM_DIR="$HOME/.nvm"
  38. [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
  39. NODE_VERSION=$(cat .nvmrc 2>/dev/null || echo "24")
  40. nvm install "$NODE_VERSION" 2>/dev/null || true
  41. nvm use "$NODE_VERSION" 2>/dev/null || true
  42. node --version
  43. npm ci
  44. ''' // Replace npm ci with INSTALL_CMD
  45. // Stash installed dependencies so parallel shards can restore them
  46. stash includes: 'node_modules/**', name: 'deps'
  47. }
  48. }
  49. stage('Lint') {
  50. steps {
  51. sh 'npm run lint' // Replace with LINT_CMD
  52. }
  53. }
  54. // Test stage - Parallel execution with sharding
  55. // Each shard restores dependencies via unstash for workspace safety
  56. stage('Test') {
  57. parallel {
  58. stage('Shard 1') {
  59. steps {
  60. unstash 'deps'
  61. // Frontend/Fullstack only — remove browser install for backend-only stacks
  62. sh 'npx playwright install --with-deps chromium' // Replace with BROWSER_INSTALL
  63. sh 'npm run test:e2e -- --shard=1/4' // Replace with TEST_CMD + shard args
  64. }
  65. }
  66. stage('Shard 2') {
  67. steps {
  68. unstash 'deps'
  69. sh 'npx playwright install --with-deps chromium' // Replace with BROWSER_INSTALL
  70. sh 'npm run test:e2e -- --shard=2/4' // Replace with TEST_CMD + shard args
  71. }
  72. }
  73. stage('Shard 3') {
  74. steps {
  75. unstash 'deps'
  76. sh 'npx playwright install --with-deps chromium' // Replace with BROWSER_INSTALL
  77. sh 'npm run test:e2e -- --shard=3/4' // Replace with TEST_CMD + shard args
  78. }
  79. }
  80. stage('Shard 4') {
  81. steps {
  82. unstash 'deps'
  83. sh 'npx playwright install --with-deps chromium' // Replace with BROWSER_INSTALL
  84. sh 'npm run test:e2e -- --shard=4/4' // Replace with TEST_CMD + shard args
  85. }
  86. }
  87. }
  88. }
  89. // Burn-in stage - Flaky test detection
  90. // Note: Burn-in targets UI flakiness. For backend-only stacks, remove this stage entirely.
  91. stage('Burn-In') {
  92. when {
  93. anyOf {
  94. changeRequest()
  95. triggeredBy 'TimerTrigger'
  96. }
  97. }
  98. steps {
  99. sh '''
  100. echo "Starting burn-in loop - detecting flaky tests"
  101. for i in $(seq 1 10); do
  102. echo "Burn-in iteration $i/10"
  103. npm run test:e2e || exit 1
  104. done
  105. echo "Burn-in complete - no flaky tests detected"
  106. ''' // Replace npm run test:e2e with TEST_CMD
  107. }
  108. }
  109. }
  110. post {
  111. always {
  112. // Archive test results and reports
  113. archiveArtifacts artifacts: 'test-results/**,playwright-report/**', allowEmptyArchive: true
  114. junit testResults: 'test-results/**/*.xml', allowEmptyResults: true
  115. }
  116. failure {
  117. echo 'Pipeline failed - check test results and artifacts'
  118. }
  119. }
  120. }