pipeline {
    agent any
    triggers {
        pollSCM('H H * * *')
    }
    tools {
        jdk 'oracle-jdk8-latest'
        maven 'apache-maven-latest'
    }
    environment {
        MVN = 'mvn -B -q -Ddoclint=none -Dadditionalparam="-Xdoclint:none" -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn'
        REPO='git@github.com:eclipse-ee4j/jstl-api.git'
        CREDENTIALS_ID='github-bot-ssh'
        BUILD_BRANCH='EE4J_8'
    }
    stages {
        stage('Fetch from git') {
            steps {
                git(branch: BUILD_BRANCH, credentialsId: CREDENTIALS_ID, url: REPO)
            }
        }
        stage('Nightly Build') {
            steps {
                withCredentials([file(credentialsId: 'secret-subkeys.asc', variable: 'KEYRING')]) {


                        //# Workaround: GPG initialization
                        sh("gpg --batch --import ${KEYRING}")
                        sh '''
                        for fpr in $(gpg --list-keys --with-colons  | awk -F: '/fpr:/ {print $10}' | sort -u);
                        do
                            echo -e "5\ny\n" |  gpg --batch --command-fd 0 --expert --edit-key $fpr trust;
                        done
                       '''
                        sh "$MVN clean install"
                }
            }
        }
    }
}

