Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 44 additions & 15 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@Library('pipeline-library@pull/1039/head') _

// Do not trigger build regularly on change requests as it costs a lot
String cronTrigger = ''
if(env.BRANCH_NAME == "master") {
Expand All @@ -9,10 +11,10 @@ def maxSplitsPerLine = 20

// Run pct tests on a limited set of repositories and their plugin(s) if not empty
// Ex: ['jenkinsci/badge-plugin\tbadge', 'jenkinsci/cron_column-plugin\tcron_column']
def limitedPluginSet = []
def limitedPluginSet = ['jenkinsci/badge-plugin\tbadge', 'jenkinsci/cron_column-plugin\tcron_column']

properties([
disableConcurrentBuilds(abortPrevious: true),
// disableConcurrentBuilds(abortPrevious: true),
buildDiscarder(logRotator(numToKeepStr: '7')),
pipelineTriggers([cron(cronTrigger)])
])
Expand Down Expand Up @@ -73,6 +75,8 @@ def results = [:]
def commit
def pctDuration
def reportNamePrefix = 'bom-report_'
def stashGlob = 'pct.sh,incrementals.sh,consume-incrementals,excludes.txt,bom-*/excludes.txt,target/pct.jar,target/megawar-REPLACEME_LINE.war'
def incrementalsBuildId = env.BUILD_ID

mavenEnv(jdk: 21) {
stage('prep') {
Expand All @@ -82,18 +86,43 @@ mavenEnv(jdk: 21) {
if (!consumeIncrementals) {
echo 'Forbidding use of incremental dependencies. If you need to consume incrementals, add the `consume-incrementals` label, or add a file named `consume-incrementals` to the repository root if you lack triage permission. Then keep this PR in draft until the dependencies have been switched to release versions.'
}
withChecks(name: 'Tests', includeStage: true) {
withEnv(['SAMPLE_PLUGIN_OPTS=-Dset.changelist', "CONSUME_INCREMENTALS=${consumeIncrementals}"]) {
sh '''
mvn -v
bash prep.sh
'''
}
if (junit(testResults: '**/target/surefire-reports/TEST-*.xml,**/target/failsafe-reports/TEST-*.xml').failCount> 0) {
error 'Some test failures during prep.sh, not going to continue'
def prepArchive = "prep-${commit}.tar.gz"
// Try to retrieve prep archive from a previous build on the same revision
try {
copyArtifacts(projectName: env.JOB_NAME, selector: lastWithArtifacts(), filter: prepArchive, fingerprintArtifacts: true)
sh('tar -xzvf ' + prepArchive + ' && rm -v ' + prepArchive)
incrementalsBuildId = readFile('target/build-id-for-incrementals.txt')
} catch(e) {
// If no corresponding prep archive found (first build or new commit), run prep.sh and prepare incrementals
withChecks(name: 'Tests', includeStage: true) {
withEnv(['SAMPLE_PLUGIN_OPTS=-Dset.changelist', "CONSUME_INCREMENTALS=${consumeIncrementals}"]) {
sh '''
mvn -v
bash prep.sh
'''
}
if (junit(testResults: '**/target/surefire-reports/TEST-*.xml,**/target/failsafe-reports/TEST-*.xml').failCount> 0) {
error 'Some test failures during prep.sh, not going to continue'
}
}
infra.prepareToPublishIncrementals()

// Add a reference file to pass infra.maybePublishIncrementals the id of the build containing the infra.prepareToPublishIncrementals() archives
writeFile file: 'target/build-id-for-incrementals.txt', text: env.BUILD_ID

// Find the last line from sample-plugin/pom.xml to avoid archiving all (heavy) megawars
def lastLine = readFile('sample-plugin/pom.xml').readLines().findAll {
it.contains('<bom>')
}.last().replaceAll(/.*<bom>|<\/bom>.*/, '')
// Replace stash glob separator by tar one then keep only the first (weekly) and last megawars
def tarGlob = stashGlob.replace(',', ' ').replace('target/megawar-REPLACEME_LINE.war', "target/megawar-weekly.war target/megawar-${lastLine}.war")
// Don't try to archive consume-incrementals file if it doesn't exist
if (!consumeIncrementalsMarkerFile) tarGlob = tarGlob.replace(' consume-incrementals', '')
// Add plugins.txt, lines.txt & build-id-for-incrementals.txt
sh('tar -czvf ' + prepArchive + ' ' + tarGlob + ' target/*.txt')
archiveArtifacts artifacts: prepArchive, fingerprint: true
sh('rm -v ' + prepArchive)
}
infra.prepareToPublishIncrementals()

fullTestMarkerFile = fileExists 'full-test'
weeklyTestMarkerFile = fileExists 'weekly-test'
Expand Down Expand Up @@ -132,7 +161,7 @@ mavenEnv(jdk: 21) {
}
def balancedSplits = splitsFromJunitRecords.collect { exclusions ->
previousRepositories - exclusions
}
}.findAll { it }
def newRepositories = currentRepositories - previousRepositories
echo "INFO: ${previousRepositories.size()} repositories returned by splitTests from junit records for '${line}' line"
echo "INFO: ${newRepositories.size()} new repositor${newRepositories.size() <= 1 ? 'y' : 'ies' } not returned by splitTests for '${line}' line"
Expand All @@ -158,7 +187,7 @@ mavenEnv(jdk: 21) {
}
stage('stash line(s)') {
lines.each { line ->
stash name: line, includes: "pct.sh,incrementals.sh,consume-incrementals,excludes.txt,bom-*/excludes.txt,target/pct.jar,target/megawar-${line}.war"
stash name: line, includes: stashGlob.replace('REPLACEME_LINE', line)
}
}
}
Expand Down Expand Up @@ -287,5 +316,5 @@ stage('checks') {
}

stage('publish incrementals') {
infra.maybePublishIncrementals()
infra.maybePublishIncrementals(incrementalsBuildId.toInteger())
}