def doCreateTask()

in vars/asfMavenTlpPlgnBuild.groovy [113:213]


def doCreateTask( os, jdk, maven, tasks, first, plan, taskContext )
{
  String label = jenkinsEnv.labelForOS(os);
  String jdkName = jenkinsEnv.jdkFromVersion(os, "${jdk}")
  String mvnName = jenkinsEnv.mvnFromVersion(os, "${maven}")
  echo "OS: ${os} JDK: ${jdk} Maven: ${maven} => Label: ${label} JDK: ${jdkName} Maven: ${mvnName}"
  if (label == null || jdkName == null || mvnName == null) {
    echo "Skipping ${os}-jdk${jdk} as unsupported by Jenkins Environment"
    return;
  }
  def cmd = [
    'mvn', '-V',
    '-DtrimStackTrace=false', 
    '-P+run-its',
    '-Dmaven.test.failure.ignore=true',
    '-Dfindbugs.failOnError=false',
    '-e',
  ]
  if (!first) {
    cmd += '-Dfindbugs.skip=true'
//  } else { // Requires authorization on SonarQube first
//    cmd += 'sonar:sonar'
  }

  if (plan == 'build') {
      cmd += 'clean'
      if (env.BRANCH_NAME == 'master' && jdk == '21' && maven == '3.9.x' && os == 'linux' ) {
        cmd += 'deploy'
      } else {
        cmd += 'verify -Dpgpverify.skip'      
      }	      
  }
  else if (plan == 'site') {
      if (taskContext.siteWithPackage) {
        cmd += 'package'
      }
      cmd += 'site'
      cmd += '-Preporting'
  }
  else if (plan == 'release') {
      cmd += 'verify'
      cmd += '-Papache-release'
  }
  def disablePublishers = !first
  first = false
  String stageId = "${os}-jdk${jdk}-m${maven}_${plan}"
  tasks[stageId] = {
    node(jenkinsEnv.nodeSelection(label)) {
      def wsDir = pwd()
      def stageDir = stageId
      if (os == 'windows' && taskContext.tmpWs) {
//      wsDir = "$TEMP\\$BUILD_TAG" // or use F:\jenkins\jenkins-slave\workspace or F:\short
        wsDir = 'F:\\short\\' + "$BUILD_TAG".replaceAll(/(.+)maven-(.+)-plugin(.*)/) { "m-${it[2]}-p${it[3]}" }
        stageDir = "j${jdk}m${maven}" + plan.take(1)
      }
      ws( dir : "$wsDir" )
      {
        stage("Build ${stageId}") {
          if (taskContext.failingFast != null) {
            cleanWs()
            echo "[FAIL FAST] ${taskContext.failingFast} has failed. Skipping ${stageId}."
          } else try {
            def localRepo = "../.maven_repositories/${env.EXECUTOR_NUMBER}"
            println "Local Repo (${stageId}): ${localRepo}"
            println "Jdk $jdkName, mvnName $mvnName"
            cmd += " -Dmaven.repo.local=../.maven_repositories/${env.EXECUTOR_NUMBER}"
            cmd += " -Dinvoker.writeJunitReport=true -B"
            withEnv(["JAVA_HOME=${ tool "$jdkName" }",
               "PATH+MAVEN=${ tool "$jdkName" }/bin:${tool "$mvnName"}/bin",
               "MAVEN_OPTS=-Xms2g -Xmx4g -Djava.awt.headless=true"]) {
             dir (stageDir) {
               checkout scm
               if (isUnix()) {
                 sh 'df -hT'
                 sh cmd.join(' ')
               } else {
                 bat 'wmic logicaldisk get size,freespace,caption'
                 bat cmd.join(' ')
                }
              }
            }
          } catch (Throwable e) {
            archiveDirs(taskContext.archives, stageDir)
            if (!taskContext.failFast) {
              throw e
            } else if (taskContext.failingFast == null) {
              taskContext.failingFast = stageId
              echo "[FAIL FAST] This is the first failure and likely root cause"
              throw e
            } else {
              echo "[FAIL FAST] ${taskContext.failingFast} had first failure, ignoring ${e.message}"
            }
          } finally {
            junit testResults: '**/target/surefire-reports/*.xml,**/target/failsafe-reports/*.xml,**/target/invoker-reports/TEST*.xml', allowEmptyResults: true
            cleanWs()
          }  
        }
      }
    }
  }
}