Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 0 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,6 @@ if you have switched the version in `bom-weekly/pom.xml` to a `*-SNAPSHOT`.

To minimize cloud resources, PCT is not run at all by default on pull requests, only some basic sanity checks.

> [!TIP]
> If you need to restart a build without any change and if you can (ex: you're a maintainer),
> prefer using replays and reruns from GitHub over empty commits to benefit from the prep archive built and saved in the previous builds.
> It saves about half an hour of total build time, and resources.

### Running weekly tests

Add the label `weekly-test` to run the tests against the latest weekly Jenkins version - This is what you want most of the time.
Expand Down
110 changes: 10 additions & 100 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,9 @@ final String[] limitedPluginSet = [
]

mavenEnv(jdk: 21) {
String prepArchiveName
stage('init') {
Map scmVars = checkout scm

// Ensure prep archive corresponds to the current state
commitId = scmVars.GIT_COMMIT.substring(0, 7)
prepArchiveName = "bom-prep-${commitId}.tar.gz"
if (fixedPrepArchiveName) {
echo "[WARNING] Using fixed prep archive name ${fixedPrepArchiveName} instead of ${prepArchiveName}"
prepArchiveName = fixedPrepArchiveName
} else {
echo "[INFO] Using prep archive name ${prepArchiveName}"
}

// Collect flags from marker files
flags.each { name, sources ->
if (fileExists(name)) {
Expand All @@ -109,36 +98,18 @@ mavenEnv(jdk: 21) {
}.join('\n')
}

stage('retrieve prep archive') {
prepFoundInBuildNumber = retrieveArtifactsFromPreviousBuilds(prepArchiveName, env.JOB_NAME)
if (prepFoundInBuildNumber == 0) {
catchError(buildResult: 'SUCCESS', stageResult: 'NOT_BUILT') { error("[SKIP] ${prepArchiveName} not found") }
return
}
}

stage('prep') {
if (prepFoundInBuildNumber == 0) {
withChecks(name: 'Tests', includeStage: true) {
withEnv(['SAMPLE_PLUGIN_OPTS=-Dset.changelist']) {
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'
}
// Publish incrementals before prep archive preparation to avoid dirty git status
infra.prepareToPublishIncrementals()
}
}
} else {
withEnv(["ARCHIVE_NAME=${prepArchiveName}"]) {
withChecks(name: 'Tests', includeStage: true) {
withEnv(['SAMPLE_PLUGIN_OPTS=-Dset.changelist']) {
sh '''
tar xzfv "${ARCHIVE_NAME}"
rm "${ARCHIVE_NAME}"
mvn -v
bash prep.sh
'''
echo "[INFO] ${prepArchiveName} retrieved and extracted, no need to run 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'
}
// Publish incrementals before prep archive preparation to avoid dirty git status
infra.prepareToPublishIncrementals()
}
}
}
Expand Down Expand Up @@ -170,10 +141,7 @@ mavenEnv(jdk: 21) {

echo "[INFO] ${allLines.size()} lines retrieved from lines.txt: ${allLines.join(' ')} "

// For archival, keeping track of newest and oldest lines as PR labels may change accross builds
// For stashes, we only care about the final lines of the current build
newestAndOldestLines = [allLines.first(), allLines.last()] // Save resources by running PCT only on newest and oldest lines
lines = newestAndOldestLines
lines = [allLines.first(), allLines.last()] // Save resources by running PCT only on newest and oldest lines
echo "[INFO] Keeping only newest and oldest lines to save resources: ${lines.join(' ')} "
if (flagEnabled(flags, 'weekly-test')) {
lines = ['weekly']
Expand All @@ -189,25 +157,6 @@ mavenEnv(jdk: 21) {
}
}

stage('archive new prep') {
if (prepFoundInBuildNumber > 0) {
catchError(buildResult: 'SUCCESS', stageResult: 'NOT_BUILT') { error("[SKIP] No new prep to archive") }
return
}

String prepArchiveGlob = 'pct.sh excludes.txt bom-*/excludes.txt target/pct.jar target/plugins.txt target/lines.txt'
// Both newest and oldest lines in the prep archive, in case labels change on PR accross builds
// ex: from weekly-test to full-test
newestAndOldestLines.each { line ->
prepArchiveGlob += " target/megawar-${line}.war"
}
withEnv(["ARCHIVE_NAME=${prepArchiveName}", "ARCHIVE_GLOB=${prepArchiveGlob}",]) {
sh 'tar czfv "${ARCHIVE_NAME}" ${ARCHIVE_GLOB}'
archiveArtifacts artifacts: prepArchiveName, fingerprint: true
echo "[INFO] New ${prepArchiveName} archived"
}
}

stage('stash prep lines') {
if (lines.isEmpty()) {
catchError(buildResult: 'SUCCESS', stageResult: 'NOT_BUILT') { error('[SKIP] No line to stash') }
Expand Down Expand Up @@ -377,42 +326,3 @@ Map parsePlugins(plugins) {
boolean flagEnabled(Map flags, String flag, String source = null) {
source ? source in flags[flag] : !flags[flag].isEmpty()
}

// Search and copy an artifact from builds of a job
// Returns the build number where it has been found, zero otherwise
int retrieveArtifactsFromPreviousBuilds(String archiveName, String jobName) {
int foundInBuildNumber = 0
boolean archiveExists = false
final int buildNumber = env.BUILD_NUMBER.toInteger()
if (buildNumber == 1) {
echo "[INFO] First build of ${jobName}, no ${archiveName} available yet"
return 0
}

// Loop over builds to retrieve the prep archive as previous build can have (only) other archive(s)
int checkBuildNumber = buildNumber - 1
// Don't loop until the first build of master '^^
final int limit = jobName.endsWith('master') ? buildNumber - 50 : 0
while (!archiveExists && checkBuildNumber > limit) {
echo "[INFO] Trying to retrieve ${archiveName} from ${jobName}#${checkBuildNumber}..."
try {
copyArtifacts(projectName: jobName,
selector: specific("${checkBuildNumber}"),
filter: archiveName,
fingerprintArtifacts: true,
optional: false,
)
archiveExists = true
} catch(e) {}
if (!archiveExists) {
checkBuildNumber = checkBuildNumber - 1
}
}
if (!archiveExists) {
echo "[INFO] No ${archiveName} found in any build of ${jobName}"
} else {
foundInBuildNumber = checkBuildNumber
echo "[INFO] ${archiveName} found in ${jobName}#${checkBuildNumber}"
}
return foundInBuildNumber
}