pipeline {
  options {
    buildDiscarder(logRotator(numToKeepStr: '10', artifactNumToKeepStr: '5'))
    disableConcurrentBuilds()
  }
  agent none
  triggers {
    pollSCM('* */15 * * *')
  }
  stages {
    stage('Build and test') {
      parallel {
        stage('Test Linux - JDK 11') {
          agent {
            label "test-cloud"
          }
          steps {
            sh '''
              set -xe
              export JAVA_HOME=/opt/oracle/openjdk11-latest
              export PATH="/opt/apache/apache-maven-3.6.3/bin:$PATH:$JAVA_HOME/bin"
              rm -rf maven-local-repository jboss-eap-8.0.0.Beta-CR1-maven-repository.zip jboss-eap-8.0.0.Beta-maven-repository
              mkdir maven-local-repository
              mvn clean install -Dmaven.repo.local=`pwd`/maven-local-repository -Dmaven.repo.path=`pwd`/maven-local-repository
            '''
          }
          post {
            always {
              junit "**/target/surefire-reports/*.xml"
              archiveArtifacts artifacts: "**/target/jboss-eap-installer-*.jar"
              cleanWs()
            }
          }
        }

        stage('Test Linux - JDK 21') {
          agent {
            label "test-cloud"
          }
          steps {
            sh '''
              set -xe
              export JAVA_HOME=/opt/oracle/jdk21-latest
              export PATH="/opt/apache/apache-maven-3.6.3/bin:$PATH:$JAVA_HOME/bin"
              rm -rf maven-local-repository jboss-eap-8.0.0.Beta-CR1-maven-repository.zip jboss-eap-8.0.0.Beta-maven-repository
              mkdir maven-local-repository
              mvn clean install -Dmaven.repo.local=`pwd`/maven-local-repository -Dmaven.repo.path=`pwd`/maven-local-repository
            '''
          }
          post {
            always {
              junit "**/target/surefire-reports/*.xml"
              archiveArtifacts artifacts: "**/target/jboss-eap-installer-*.jar"
              cleanWs()
            }
          }
        }

        stage('Test Windows JDK 11') {
          agent {
            label "windows-test"
          }
          steps {
            sh '''
              set -xe
              echo $PATH
              export JAVA_HOME="C:\\Program Files\\Java\\jdk-11"
              export M2_HOME="C:\\Program Files\\Apache Maven\\apache-maven-3.6.3"
              export PATH="${M2_HOME}\\bin:${PATH}"
              rm -rf maven-local-repository
              mkdir maven-local-repository
              mvn clean install -Dmaven.repo.local=`pwd`/maven-local-repository -Dmaven.repo.path=`pwd`/maven-local-repository  -Djdk.tls.client.protocols=TLSv1.2 -Dorg.jboss.installer.test.server_startup=120
            '''
          }
          post {
            always {
              junit "**/target/surefire-reports/*.xml"
              archiveArtifacts artifacts: "**/target/jboss-eap-installer-*.jar"
              cleanWs()
            }
          }
        }

        stage('Test Windows JDK 21') {
          agent {
            label "windows-test"
          }
          steps {
            sh '''
              set -xe
              echo $PATH
              export JAVA_HOME="C:\\Program Files\\Java\\jdk-21"
              export M2_HOME="C:\\Program Files\\Apache Maven\\apache-maven-3.6.3"
              export PATH="${M2_HOME}\\bin:${PATH}"
              rm -rf maven-local-repository
              mkdir maven-local-repository
              mvn clean install -Dmaven.repo.local=`pwd`/maven-local-repository -Dmaven.repo.path=`pwd`/maven-local-repository  -Djdk.tls.client.protocols=TLSv1.2 -Dorg.jboss.installer.test.server_startup=120
            '''
          }
          post {
            always {
              junit "**/target/surefire-reports/*.xml"
              archiveArtifacts artifacts: "**/target/jboss-eap-installer-*.jar"
              cleanWs()
            }
          }
        }
      }
    }
  }
}
