2016-09-18 11:29:26 +08:00
|
|
|
#!/usr/bin/env groovy
|
|
|
|
|
2016-01-21 00:42:31 +08:00
|
|
|
/*
|
2017-02-26 02:56:01 +08:00
|
|
|
* This Jenkinsfile is intended to run on https://ci.jenkins.io and may fail anywhere else.
|
2016-01-21 00:42:31 +08:00
|
|
|
* It makes assumptions about plugins being installed, labels mapping to nodes that can build what is needed, etc.
|
|
|
|
*/
|
|
|
|
|
2019-10-24 04:54:04 +08:00
|
|
|
def buildNumber = BUILD_NUMBER as int; if (buildNumber > 1) milestone(buildNumber - 1); milestone(buildNumber) // JENKINS-43353 / JENKINS-58625
|
|
|
|
|
2016-01-21 00:42:31 +08:00
|
|
|
// TEST FLAG - to make it easier to turn on/off unit tests for speeding up access to later stuff.
|
|
|
|
def runTests = true
|
2017-01-04 04:15:12 +08:00
|
|
|
def failFast = false
|
2016-01-21 00:42:31 +08:00
|
|
|
|
2019-02-10 07:45:20 +08:00
|
|
|
properties([buildDiscarder(logRotator(numToKeepStr: '50', artifactNumToKeepStr: '3')), durabilityHint('PERFORMANCE_OPTIMIZED')])
|
2016-01-21 00:42:31 +08:00
|
|
|
|
2019-10-25 18:15:01 +08:00
|
|
|
// TODO: Restore 'Windows' once https://groups.google.com/forum/#!topic/jenkinsci-dev/v9d-XosOp2s is resolved
|
|
|
|
def buildTypes = ['Linux']
|
2018-12-12 23:41:04 +08:00
|
|
|
def jdks = [8, 11]
|
2016-01-21 00:42:31 +08:00
|
|
|
|
2017-01-04 04:15:12 +08:00
|
|
|
def builds = [:]
|
|
|
|
for(i = 0; i < buildTypes.size(); i++) {
|
2018-09-29 02:46:29 +08:00
|
|
|
for(j = 0; j < jdks.size(); j++) {
|
2017-01-04 04:15:12 +08:00
|
|
|
def buildType = buildTypes[i]
|
2018-09-29 02:46:29 +08:00
|
|
|
def jdk = jdks[j]
|
|
|
|
builds["${buildType}-jdk${jdk}"] = {
|
2019-07-27 13:54:24 +08:00
|
|
|
// see https://github.com/jenkins-infra/documentation/blob/master/ci.adoc#node-labels for information on what node types are available
|
|
|
|
node(buildType == 'Linux' ? (jdk == 8 ? 'maven' : 'maven-11') : buildType.toLowerCase()) {
|
2017-01-04 04:15:12 +08:00
|
|
|
// First stage is actually checking out the source. Since we're using Multibranch
|
|
|
|
// currently, we can use "checkout scm".
|
|
|
|
stage('Checkout') {
|
|
|
|
checkout scm
|
2016-01-21 01:48:43 +08:00
|
|
|
}
|
2016-01-28 22:56:22 +08:00
|
|
|
|
2018-05-03 22:13:39 +08:00
|
|
|
def changelistF = "${pwd tmp: true}/changelist"
|
|
|
|
def m2repo = "${pwd tmp: true}/m2repo"
|
|
|
|
|
2017-01-04 04:15:12 +08:00
|
|
|
// Now run the actual build.
|
|
|
|
stage("${buildType} Build / Test") {
|
|
|
|
timeout(time: 180, unit: 'MINUTES') {
|
|
|
|
// See below for what this method does - we're passing an arbitrary environment
|
|
|
|
// variable to it so that JAVA_OPTS and MAVEN_OPTS are set correctly.
|
2017-04-03 21:43:42 +08:00
|
|
|
withMavenEnv(["JAVA_OPTS=-Xmx1536m -Xms512m",
|
2019-07-27 13:54:24 +08:00
|
|
|
"MAVEN_OPTS=-Xmx1536m -Xms512m"], buildType, jdk) {
|
2017-01-04 04:15:12 +08:00
|
|
|
// Actually run Maven!
|
2017-04-27 23:35:27 +08:00
|
|
|
// -Dmaven.repo.local=… tells Maven to create a subdir in the temporary directory for the local Maven repository
|
2019-11-26 05:26:22 +08:00
|
|
|
def mvnCmd = "mvn -Pdebug -U -Dset.changelist help:evaluate -Dexpression=changelist -Doutput=$changelistF clean install ${runTests ? '-Dmaven.test.failure.ignore' : '-DskipTests'} -V -B -ntp -Dmaven.repo.local=$m2repo -s settings-azure.xml -e"
|
2018-09-29 02:46:29 +08:00
|
|
|
|
2017-01-04 04:15:12 +08:00
|
|
|
if(isUnix()) {
|
|
|
|
sh mvnCmd
|
2019-01-04 04:41:57 +08:00
|
|
|
sh 'git add . && git diff --exit-code HEAD'
|
2017-01-04 04:15:12 +08:00
|
|
|
} else {
|
2017-06-27 03:19:27 +08:00
|
|
|
bat mvnCmd
|
2017-01-04 04:15:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Once we've built, archive the artifacts and the test results.
|
2017-11-17 11:49:13 +08:00
|
|
|
stage("${buildType} Publishing") {
|
2017-01-04 04:15:12 +08:00
|
|
|
if (runTests) {
|
2017-12-02 01:04:16 +08:00
|
|
|
junit healthScaleFactor: 20.0, testResults: '*/target/surefire-reports/*.xml'
|
2018-12-12 22:04:59 +08:00
|
|
|
archiveArtifacts allowEmptyArchive: true, artifacts: '**/target/surefire-reports/*.dumpstream'
|
2017-01-04 04:15:12 +08:00
|
|
|
}
|
2019-02-05 22:45:50 +08:00
|
|
|
if (buildType == 'Linux' && jdk == jdks[0]) {
|
2018-05-03 22:13:39 +08:00
|
|
|
def changelist = readFile(changelistF)
|
|
|
|
dir(m2repo) {
|
|
|
|
archiveArtifacts artifacts: "**/*$changelist/*$changelist*",
|
2019-01-29 04:33:09 +08:00
|
|
|
excludes: '**/*.lastUpdated,**/jenkins-test*/',
|
2018-05-07 21:39:26 +08:00
|
|
|
allowEmptyArchive: true, // in case we forgot to reincrementalify
|
2018-05-03 22:13:39 +08:00
|
|
|
fingerprint: true
|
|
|
|
}
|
|
|
|
}
|
2017-01-04 04:15:12 +08:00
|
|
|
}
|
2016-01-21 07:52:06 +08:00
|
|
|
}
|
2016-01-21 00:42:31 +08:00
|
|
|
}
|
2018-09-29 02:46:29 +08:00
|
|
|
}}
|
2016-01-21 00:42:31 +08:00
|
|
|
|
2019-10-25 18:15:01 +08:00
|
|
|
// TODO: Restore ATH once https://groups.google.com/forum/#!topic/jenkinsci-dev/v9d-XosOp2s is resolved
|
2018-09-29 02:46:29 +08:00
|
|
|
// TODO: ATH flow now supports Java 8 only, it needs to be reworked (INFRA-1690)
|
2018-03-14 18:24:14 +08:00
|
|
|
builds.ath = {
|
2018-03-26 23:42:19 +08:00
|
|
|
node("docker&&highmem") {
|
2018-03-20 21:56:25 +08:00
|
|
|
// Just to be safe
|
|
|
|
deleteDir()
|
2018-03-14 18:24:14 +08:00
|
|
|
def fileUri
|
|
|
|
def metadataPath
|
|
|
|
dir("sources") {
|
|
|
|
checkout scm
|
2018-03-14 22:02:20 +08:00
|
|
|
withMavenEnv(["JAVA_OPTS=-Xmx1536m -Xms512m",
|
2018-09-29 02:46:29 +08:00
|
|
|
"MAVEN_OPTS=-Xmx1536m -Xms512m"], 8) {
|
2019-11-26 22:08:48 +08:00
|
|
|
sh "mvn --batch-mode --show-version -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -DskipTests -am -pl war package -Dmaven.repo.local=${pwd tmp: true}/m2repo -s settings-azure.xml"
|
2018-03-14 22:02:20 +08:00
|
|
|
}
|
2018-03-14 18:24:14 +08:00
|
|
|
dir("war/target") {
|
|
|
|
fileUri = "file://" + pwd() + "/jenkins.war"
|
|
|
|
}
|
|
|
|
metadataPath = pwd() + "/essentials.yml"
|
|
|
|
}
|
2018-03-13 17:26:05 +08:00
|
|
|
dir("ath") {
|
2018-03-14 18:24:14 +08:00
|
|
|
runATH jenkins: fileUri, metadataFile: metadataPath
|
2018-03-13 17:26:05 +08:00
|
|
|
}
|
|
|
|
}
|
2019-10-31 23:03:59 +08:00
|
|
|
}
|
2018-03-13 17:26:05 +08:00
|
|
|
|
2018-03-14 18:24:14 +08:00
|
|
|
builds.failFast = failFast
|
|
|
|
parallel builds
|
2018-05-03 22:13:39 +08:00
|
|
|
infra.maybePublishIncrementals()
|
2018-03-14 18:24:14 +08:00
|
|
|
|
2016-01-21 00:42:31 +08:00
|
|
|
// This method sets up the Maven and JDK tools, puts them in the environment along
|
|
|
|
// with whatever other arbitrary environment variables we passed in, and runs the
|
|
|
|
// body we passed in within that environment.
|
2019-07-27 13:54:24 +08:00
|
|
|
void withMavenEnv(List envVars = [], def buildType, def javaVersion, def body) {
|
|
|
|
if (buildType == 'Linux') {
|
|
|
|
// I.e., a Maven container using ACI. No need to install tools.
|
|
|
|
return withEnv(envVars) {
|
|
|
|
body.call()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-21 00:42:31 +08:00
|
|
|
// The names here are currently hardcoded for my test environment. This needs
|
|
|
|
// to be made more flexible.
|
|
|
|
// Using the "tool" Workflow call automatically installs those tools on the
|
|
|
|
// node.
|
2016-09-18 11:29:26 +08:00
|
|
|
String mvntool = tool name: "mvn", type: 'hudson.tasks.Maven$MavenInstallation'
|
2018-09-29 02:46:29 +08:00
|
|
|
String jdktool = tool name: "jdk${javaVersion}", type: 'hudson.model.JDK'
|
2016-01-21 00:42:31 +08:00
|
|
|
|
|
|
|
// Set JAVA_HOME, MAVEN_HOME and special PATH variables for the tools we're
|
|
|
|
// using.
|
|
|
|
List mvnEnv = ["PATH+MVN=${mvntool}/bin", "PATH+JDK=${jdktool}/bin", "JAVA_HOME=${jdktool}", "MAVEN_HOME=${mvntool}"]
|
|
|
|
|
|
|
|
// Add any additional environment variables.
|
|
|
|
mvnEnv.addAll(envVars)
|
|
|
|
|
|
|
|
// Invoke the body closure we're passed within the environment we've created.
|
|
|
|
withEnv(mvnEnv) {
|
|
|
|
body.call()
|
|
|
|
}
|
|
|
|
}
|