Skip to content

Instantly share code, notes, and snippets.

@bogdanRada
Forked from Jotschi/Jenkinsfile
Created July 31, 2019 06:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bogdanRada/0414879442ab10ee8a6ec5303aff9f79 to your computer and use it in GitHub Desktop.
Save bogdanRada/0414879442ab10ee8a6ec5303aff9f79 to your computer and use it in GitHub Desktop.
stage 'Test'
// Split the previously executed tests into 10 jobs
def splits = splitTests parallelism: [$class: 'CountDrivenParallelism', size: 10], generateInclusions: true
def branches = [:]
// Prepare each job
for (int i = 0; i < splits.size(); i++) {
def split = splits[i]
branches["split${i}"] = {
// The job should allocate a new jenkins slave
node('dockerSlave') {
// Checkout the code
checkout scm
// Write exclusion and inclusion files
writeFile file: (split.includes ? 'inclusions.txt' : 'exclusions.txt'), text: split.list.join("\n")
writeFile file: (split.includes ? 'exclusions.txt' : 'inclusions.txt'), text: ''
def mvnHome = tool 'M3'
// Execute the tests
sh "${mvnHome}/bin/mvn -B clean test -Dmaven.test.failure.ignore"
// Aggregate the junit test results
step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/*.xml'])
}
}
}
// Execute all jobs in parallel
parallel branches
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment