Skip to content

Commit

Permalink
HSEARCH-4924 Jenkinsfile: For the default build, always pre-build sou…
Browse files Browse the repository at this point in the history
…rces in a different execution, even on primary branches

Because:

1. It's simpler that way.
2. It could actually be a benefit because we'd fail fast on things like
   bad formatting in one of the last modules.
  • Loading branch information
yrodiere committed Aug 28, 2023
1 parent a90ad0d commit 8afbe47
Showing 1 changed file with 37 additions and 31 deletions.
68 changes: 37 additions & 31 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -383,44 +383,54 @@ stage('Default build') {
}
runBuildOnNode( NODE_PATTERN_BASE, [time: 2, unit: 'HOURS'] ) {
withMavenWorkspace(mavenSettingsConfig: deploySnapshot ? helper.configuration.file.deployment.maven.settingsId : null) {
boolean sonarEnabled = enableDefaultBuildIT && helper.configuration.file?.sonar?.credentials
if (incrementalBuild && sonarEnabled) {
// We won't be building all classes in the incremental build,
// which is a problem for Sonar since it needs access to compiled classes.
// So in incremental builds, we build all sources first, but skipping tests.
sh """ \
mvn clean install \
--fail-at-end \
-Pdist -Pjqassistant -Pci-sources-check \
-DskipITs -DskipTests \
${toTestJdkArg(environments.content.jdk.default)} \
"""
dir(helper.configuration.maven.localRepositoryPath) {
unstash name:'default-build-result'
}
}
// If we are in the pull request we've already run JQAssistant and source formatting checks
String mavenArgs = """ \
String commonMavenArgs = """ \
--fail-at-end \
-Pdist -Pcoverage \
${incrementalBuild ? ('-Dincremental -Dgib.referenceBranch=refs/remotes/origin/'+helper.scmSource.pullRequest.target.name) : '-Pjqassistant -Pci-sources-check'} \
${enableDefaultBuildIT ? '' : '-DskipITs'} \
${toTestJdkArg(environments.content.jdk.default)} \
"""
pullContainerImages( mavenArgs )

echo "Building code and running unit tests and basic checks."
sh """ \
mvn clean \
mvn \
${commonMavenArgs} \
-Pjqassistant -Pci-sources-check \
-DskipITs \
${toTestJdkArg(environments.content.jdk.default)} \
clean \
${deploySnapshot ? "\
deploy \
" : "\
install \
"} \
$mavenArgs \
"""
dir(helper.configuration.maven.localRepositoryPath) {
unstash name:'default-build-result'
}

if (!enableDefaultBuildIT) {
echo "Skipping integration tests in the default environment."
return
}

// Don't try to report to SonarCloud if coverage data is missing
if (sonarEnabled) {
def sonarCredentialsId = helper.configuration.file.sonar.credentials
echo "Running integration tests in the default environment."
String allITProjects = sh(script: "./ci/list-dependent-integration-tests.sh hibernate-search-engine", returnStdout: true).trim()
String itMavenArgs = """ \
${commonMavenArgs} \
-pl ${allITProjects} \
${incrementalBuild ?
('-Dincremental -Dgib.referenceBranch=refs/remotes/origin/'+helper.scmSource.pullRequest.target.name)
: ''
} \
"""
pullContainerImages( itMavenArgs )
sh """ \
mvn \
${itMavenArgs} \
verify \
"""

def sonarCredentialsId = helper.configuration.file?.sonar?.credentials
if (sonarCredentialsId) {
// WARNING: Make sure credentials are evaluated by sh, not Groovy.
// To that end, escape the '$' when referencing the variables.
// See https://www.jenkins.io/doc/book/pipeline/jenkinsfile/#string-interpolation
Expand Down Expand Up @@ -449,11 +459,7 @@ stage('Default build') {
}
}
else {
echo "Skipping Sonar report."
}

dir(helper.configuration.maven.localRepositoryPath) {
stash name:'default-build-result', includes:"org/hibernate/search/**"
echo "Skipping Sonar report: no credentials."
}
}
}
Expand Down

0 comments on commit 8afbe47

Please sign in to comment.