pipeline { agent { kubernetes { inheritFrom 'centos-7' } } environment { DOWNSTREAM_JOBS = 'xtext-extras' GRADLE_USER_HOME = "$WORKSPACE/.gradle" // workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=564559 } parameters { // see https://wiki.eclipse.org/Jenkins#JDK choice(name: 'JDK_VERSION', description: 'Which JDK should be used?', choices: [ 'temurin-jdk8-latest', 'temurin-jdk11-latest', 'temurin-jdk17-latest' ]) booleanParam( name: 'TRIGGER_DOWNSTREAM_BUILD', defaultValue: (env.BRANCH_NAME.startsWith('milestone')||env.BRANCH_NAME.startsWith('release')), description: 'Should downstream jobs for the same branch be triggered on successful build?' ) } options { buildDiscarder(logRotator(numToKeepStr:'15')) disableConcurrentBuilds() timeout(time: 120, unit: 'MINUTES') } tools { maven "apache-maven-3.8.4" jdk "${params.JDK_VERSION}" } // Build stages stages { stage('Initialize') { steps { checkout scm script { currentBuild.displayName = String.format("#%s(JDK%s)", BUILD_NUMBER, javaVersion()) } } } stage('Gradle Build') { steps { sh './1-gradle-build.sh' } } stage('Maven Build') { steps { sh './2-maven-build.sh' } } } post { always { junit testResults: '**/build/test-results/test/*.xml' } success { archiveArtifacts artifacts: 'build/**' script { if (params.TRIGGER_DOWNSTREAM_BUILD==true) { DOWNSTREAM_JOBS.split(',').each { def downstreamUrl = new URL("${env.JENKINS_URL}/job/$it/job/${env.BRANCH_NAME}") def boolean downstreamJobExists = sh(script: "curl -L -s -o /dev/null -I -w '%{http_code}' ${downstreamUrl}", returnStdout: true) == "200" if (downstreamJobExists) { build job: "$it/${env.BRANCH_NAME}", wait: false, parameters: [booleanParam(name: 'TRIGGER_DOWNSTREAM_BUILD', value: "${params.TRIGGER_DOWNSTREAM_BUILD}"), string(name: 'JDK_VERSION', value: "${params.JDK_VERSION}")] } } } } } cleanup { script { def curResult = currentBuild.currentResult def lastResult = 'NEW' if (currentBuild.previousBuild != null) { lastResult = currentBuild.previousBuild.result } if (curResult != 'SUCCESS' || lastResult != 'SUCCESS') { def color = '' switch (curResult) { case 'SUCCESS': color = '#00FF00' break case 'UNSTABLE': color = '#FFFF00' break case 'FAILURE': color = '#FF0000' break default: // e.g. ABORTED color = '#666666' } slackSend ( message: "${lastResult} => ${curResult}: <${env.BUILD_URL}|${env.JOB_NAME}#${env.BUILD_NUMBER}>", botUser: true, channel: 'xtext-builds', color: "${color}" ) } } } } } /** return the Java version as Integer (8, 11, ...) */ def javaVersion() { return Integer.parseInt(params.JDK_VERSION.replaceAll(".*-jdk(\\d+).*", "\$1")) }