#!groovy

pipeline {

  agent none

  stages {
    stage('BuildAndTest') {
      parallel {
        stage('linux:openjdk-11-hotspot') {
          agent { label 'linux' }
          tools {
            jdk   'openjdk-11-hotspot'
            maven 'maven-3.6.0'
          }
          steps {
            withMaven(
              maven: 'maven-3.6.0',
              mavenLocalRepo: '.repository') {
              sh 'mvn -C -e -U clean install site'
            }
          }
        }
      }
    }

    stage('Deploy') {
      when { buildingTag() }
      steps {
        withMaven(
          maven: 'maven-3.6.0',
          mavenLocalRepo: '.repository') {
          sh 'mvn -P arc7-deploy -C -e deploy'
        }
      }
    }
  }

  post {
    success {
      node('mustard') {
        script {
          withMaven(
            maven: 'maven-3.6.0',
            mavenLocalRepo: '.repository') {
            withCredentials([
              usernamePassword(
                credentialsId: 'arc7-jms-credentials',
                passwordVariable: 'JENKINS_JMS_PASSWORD',
                usernameVariable: 'JENKINS_JMS_USER'
              ),
              file(
                credentialsId: 'arc7-jenkins-trust-store',
                variable: 'JENKINS_JMS_TRUST_STORE'
              ),
              string(
                credentialsId: 'arc7-jenkins-trust-store-password',
                variable: 'JENKINS_JMS_TRUST_STORE_PASSWORD'
              )
            ]) {
              sh ".jenkins/notify.sh success"
            }
          }
        }
      }
    }
    failure {
      node('mustard') {
        script {
          withMaven(
            maven: 'maven-3.6.0',
            mavenLocalRepo: '.repository') {
            withCredentials([
              usernamePassword(
                credentialsId: 'arc7-jms-credentials',
                passwordVariable: 'JENKINS_JMS_PASSWORD',
                usernameVariable: 'JENKINS_JMS_USER'
              ),
              file(
                credentialsId: 'arc7-jenkins-trust-store',
                variable: 'JENKINS_JMS_TRUST_STORE'
              ),
              string(
                credentialsId: 'arc7-jenkins-trust-store-password',
                variable: 'JENKINS_JMS_TRUST_STORE_PASSWORD'
              )
            ]) {
              sh ".jenkins/notify.sh failure"
            }
          }
        }
      }
    }
  }

}